lundi 3 décembre 2018

passing lambda to void specified template fails

i simplified the problem as much as i could so here is the function in question:

class Test
{
public:
    template<class T>
    void ExecuteFunction(std::function<void(T)> f)
    {
    }
};

if i call the function with int-typing everything works fine, however, if i call it with a void-typed lambda it doesn't compile anymore.

Test test;

test.ExecuteFunction<void>(    // doesn't compile
    [](void)->void
{
    int i = 5;
});

test.ExecuteFunction<int>(    // this compiles
    [](int)->void
{
    int i = 5;
});

Compiler errors:

Error   C2672   'Test::ExecuteFunction': no matching overloaded function found  
Error   C2770   invalid explicit template argument(s) for 'void Test::ExecuteFunction(std::function<void(P)>)'  
Error (active)      no instance of function template "Test::ExecuteFunction" matches the argument list

is there a way around this? how would someone specify the template so that both calls work?

Aucun commentaire:

Enregistrer un commentaire