lundi 5 décembre 2016

Is it possible to return an object of type T by reference from a lambda without using trailing return type sintax?

Given the following code snippet:

struct T {}; 

std::function<T&(T&)> f = [](T& obj) -> T& { return obj; };

I was wondering if it is possible to infer the correct lambda return type (i.e. T&) without using trailing return type syntax.

Obviously, if I remove -> T& then a compile-time error will occur in that the deduced type would be T.

Aucun commentaire:

Enregistrer un commentaire