I was wondering why this code does not compile:
#include "stdafx.h" #include <functional> bool Run(std::function<bool()> f) { return f(); } void Run(std::function<void()> f) { f(); } int _tmain(int argc, _TCHAR* argv[]) { Run([] { return true; }); Run([] {}); return 0; }
Both calls to Run() trigger C2668: 'Run' : ambiguous call to overloaded function.
If I define overloaded functions that differ only in their return types then the compiler can't figure out which one to pick - granted.
The parameters to Run() are implicitly augmented to this notation:
Run([] (void) -> bool { return true; });
Run([] (void) -> void {});
So I assumed that the template "std::function" would expand to something like "__mangling_void_bool_mangling__" in the first case and to something like "__mangling_void_void_mangling__" in the second case; effectively defining two different types for paramter f in the overloaded versions of Run().
But the compiler seems to treat the std::function parameter f like a plain old void* pointer without any type information.
Is that correct?