I have a strange error I don't really understand, with VS2013. It's just a simplification of my real problem resulting in the same error.
std::function<bool()> x = (someCondition == true)
? []() { return true; }
: []() { return false; };
VS Compiler error is:
1>f:\test\cppconsoleapplication\cppconsoleapplication.cpp(497): error C2446: ':' : no conversion from 'main::<lambda_96d01fe3721e46e4e8217a69a07d151b>' to 'main::<lambda_0d38919a9b2aba5caf910d83eac11776>'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
IntelliSense even came up with this mysterious error message:
IntelliSense: more than one operator "?" matches these operands:
built-in operator "expression ? pointer : pointer"
built-in operator "expression ? pointer : pointer"
built-in operator "expression ? pointer : pointer"
built-in operator "expression ? pointer : pointer"
operand types are: lambda []bool ()->bool : lambda []bool ()->bool f:\Test\CppConsoleApplication\CppConsoleApplication.cpp 496
whereas the following compiles
std::function<bool()> x = []() { return true; };
if (someCondition == false)
x = []() { return false; };
Is it just one of VisualStudio's bugs or what am I doing wrong here?