Lee Howes

Lee Howes LeeHowes

Niner since 2010


  • C++ and Beyond 2011: Benedict Gaster on C++11, C++ AMP, C++ Renaissance

    No overload though; maybe that was the issue.

    Right. If you take two function overloads:

    void foo(std::function<void(int)>);

    void foo(std::function<void(float)>);

    And pass a lambda to them:

    foo( [](float a){return a + 1.f;} );

    It won't work because you can't overload on the lambda itself, and you can't overload on std::function because it needs to resolve the overload before it knows which std::function to try to construct from the lambda. The problem of course is that the type of the lambda is not the type of its bracket operator, which is what you really need in the above. You can do tricks like indirect through a function and grab the bracket operator type then use that (maybe via a fuction reference) for overloading but it's clumsy and doesn't then distinguish between lambdas and std::function very well because you can't do overload resolution between std::function and lambdas.


    I don't really see auto as a problem either, though. It's no more of an issue than using short variable names. Either way you can lose too much information too quickly, and fixing that is the job of a coding standard.