“[](unsigned char x)”是什么意思?

What does the mean "[](unsigned char x)"?

什么意思[](unsigned char x)

这是我的代码:

#include <algorithm>

std::string str1 = "Text with some     spaces";

str1.erase(std::remove(str1.begin(), str1.end(), ' '), str1.end());

std::cout << str1 << '\n';

std::string str2 = "Text\n with\tsome \t whitesspaces\n\n";

str2.erase(std::remove_if(str2.begin(), str2.end(), [](unsigned char x) {return std::isspace(x);}), str2.end());

std::cout << str2 <<'\n';

这是 lambda 函数定义的开始:

[](unsigned char x) {
    return std::isspace(x);
}

这定义了一个接收 unsigned char 和 returning int 的临时函数(由 std::isspace 的 return 值自动确定,因为lambda 没有指定 return 类型)。