visual studio 2010 - Cannot initialize unordered_map from int -
i've got strange problem. msvc doesn't have initializer lists, i've used lambda approximate them.
static const std::unordered_map<std::wstring, lexedfile::token> reserved_words = []() -> std::unordered_map<std::wstring, lexedfile::token> { std::unordered_map<std::wstring, lexedfile::token> retval; // stuff retval return retval; }();
msvc throws compiler error.
error c2440: 'initializing' : cannot convert 'int' 'std::tr1::unordered_map<_kty,_ty>'
unless i'm quite blind, there's no "int" anywhere near this. don't see what's wrong. suggestions?
edit:
there's nothing funky // stuff retval
, it's bunch of insertions, , function-scope static variable in lambda in member function.
auto next = [&] { static const std::unordered_map<std::wstring, lexedfile::token> reserved_words = []() -> std::unordered_map<std::wstring, lexedfile::token> { std::unordered_map<std::wstring, lexedfile::token> retval; retval[l"namespace"] = lexedfile::token::namespace; retval[l"for"] = lexedfile::token::for; retval[l"while"] = lexedfile::token::while; retval[l"do"] = lexedfile::token::do; retval[l"switch"] = lexedfile::token::switch; retval[l"case"] = lexedfile::token::case; retval[l"default"] = lexedfile::token::default; retval[l"try"] = lexedfile::token::try; retval[l"catch"] = lexedfile::token::catch; retval[l"auto"] = lexedfile::token::auto; retval[l"type"] = lexedfile::token::type; retval[l"break"] = lexedfile::token::break; retval[l"continue"] = lexedfile::token::continue; retval[l"return"] = lexedfile::token::return; retval[l"static"] = lexedfile::token::static; retval[l"sizeof"] = lexedfile::token::sizeof; retval[l"decltype"] = lexedfile::token::decltype; retval[l"if"] = lexedfile::token::if; retval[l"else"] = lexedfile::token::else; return retval; }(); if (stack.empty()) return; std::wstring token(stack.begin(), stack.end()); stack.clear(); if (reserved_words.find(token) != reserved_words.end()) { l.tokens.push_back(reserved_words.find(token)->second); return; } l.tokens.push_back(lexedfile::identifier); };
the compiler accept if use constructor directly not initialization, seems strange. compiler bug.
calling constructor () instead of using = works fine, i'm marking 1 compiler error.
Comments
Post a Comment