小编Alt*_*mor的帖子

与GCC/MSVC中的lambda转换构造函数的差异

哪一个,如果不是两个,都打破了规范?在MSVC 2013和MSVC 2013年11月CTP上尝试使用MSVC,GCC是MinGW x64 4.9.1,-std = c ++ 11.

template<typename ret_type>
class memoizer
{
    using func_type = ret_type(*)(const int);
    const func_type func;

    std::map<int, ret_type> cache;

public:
    memoizer(func_type func) : func(func)
    {
    }

    ret_type operator [](const int n)
    {
        const auto it = cache.find(n);
        if(it != cache.end())
            return it->second;

        return cache[n] = func(n);
    }
};

//works in GCC but not MSVC
//error C2065: 'fib' : undeclared identifier
memoizer<int64_t> fib([](const int n)
{
    return n < 2 ? n : fib[n - …
Run Code Online (Sandbox Code Playgroud)

c++ gcc visual-c++ c++11

4
推荐指数
1
解决办法
265
查看次数

标签 统计

c++ ×1

c++11 ×1

gcc ×1

visual-c++ ×1