mercredi 7 janvier 2015

Finding out the return type of a function, lambda or function

This seems to be solved for the case of lambdas in this question. But it is a 2011 answer and I'm looking for a general case: lambdas, regular functions, and functors. And, if possible, by means of the most modern c++ language additions. (Note: g++ -std=c++1y test.cpp).


So, given a function (or a lambda), I'm trying to find out what's its return type. For instance, to declare a variable (simplified case).



int h (int i) {
return 2*i;
}

int main () {
// any of the following should be equivalent to int a; int b; int c;
decltype(h) a; // <<<<< wrong, a's type is not int
result_of(h) b; // <<<<<< wrong, doesn't compile
result_of<decltype(h)> c; // <<<<<< wrong c's type is not int
}


Thanks.


Aucun commentaire:

Enregistrer un commentaire