I'm not sure it is possible with lambdas, it's looking rather like a polymorphic lambda.
check here[
^]. I just don't think lambdas were intended to be used in the context of template based generic programming.
The closest I have managed to get to implementing what you have above is this:
template <typename T>
T& func(T& val)
{
val++;
return val;
}
template <typename T, T&(*Func)(T&) = func<T>>
class SomeClass
{
public:
SomeClass() : val(0) {};
void CallIt()
{
std::cout << "val before call = " << val << std::endl;
Func(val);
std::cout << "val after call = " << val << std::endl;
}
private:
T val;
};
int main(int argc, char* argv[])
{
SomeClass<int> instance;
instance.CallIt();
return 0;
}
But then that doesn't help with your original question wrt playing around with lambdas, and it is also probably just as simple to use a functor in my particular example.
I'd love to here if someone managed to do this, or by using
std::function
as a wrapper for a lambda.