相关疑难解决方法(0)

在G ++ 4.7中的内联函数中定义时未找到Lambda

我在头文件中定义了以下函数(该库是目标只是头文件的一部分):

typedef bool (*FieldComparer)(const std::string&, const std::string&);

inline FieldComparer
GetComparer(const std::string& query, string& separator)
{
    if (query.find('=') != std::string::npos) {
        separator = "=";
        return [](const string& s1, const string& s2) { return s1 == s2; };
    }
    else if (query.find('^') != string::npos) {
        separator = "^";
        return [](const string& s1, const string& s2) { return boost::starts_with(s1, s2); };
    }
    else if (query.find('*') != string::npos) {
        separator = "*";
        return [](const string& s1, const string& s2) { return boost::contains(s1, s2); }; …
Run Code Online (Sandbox Code Playgroud)

c++ c++11 gcc4.7

31
推荐指数
1
解决办法
1165
查看次数

C++ 0x lambda,我怎么能作为参数传递?

请查看以下C++ 0x lambda相关代码:

typedef uint64_t (*WEIGHT_FUNC)(void* param);
typedef std::map<std::string, WEIGHT_FUNC> CallbackTable;

CallbackTable table;
table["rand_weight"] = [](void* param) -> uint64_t
{
  return (rand() % 100 + 1);
};
Run Code Online (Sandbox Code Playgroud)

我得到一个错误(在Visual Studio 2010中),lambda无法转换为类型WEIGHT_FUNC.我也知道答案:使用std::function object:

typedef std::function<uint64_t (void*)>  WEIGHT_FUNC;
Run Code Online (Sandbox Code Playgroud)

但是,我也想知道如何在不使用的情况下接收lambda的类型std::function.它应该是什么类型的?

c++ lambda c++11

17
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×2

c++11 ×2

gcc4.7 ×1

lambda ×1