哪一个,如果不是两个,都打破了规范?在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)