#include <iostream>
#include <functional>
template<typename T,typename R>
struct match_struct{
T t;
std::function<R(T)> f;
};
template<typename T,typename R>
match_struct<T,R> match(T t,std::function<R(T)>f) {
return match_struct<T,R>{t,f};
}
int main(int argc, char *argv[])
{
auto m = match<int,int>(10, [](int i){ return i;});
return 0;
}
I know that I have to specify the types explicitly when I want to create a struct/class. I thought that I could just create a templated function that would infer the types automatically.
So that I can just write
auto m = match(10, [](int i){ return i;});
Unfortunately that doesn't work.
Is there a workaround for this? So that I don't have to specify the types explicitly?