Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

decltype for member functions

How can I get the return type of a member function in the following example?

template <typename Getter>
class MyClass {
   typedef decltype(mygetter.get()) gotten_t;
 ...
};

The problem, of course, is that I don't have a "mygetter" object while defining MyClass.

What I'm trying to do is: I'm creating a cache that can use, as it's key, whatever is returned by the getter.

like image 313
Martin C. Martin Avatar asked Apr 13 '12 17:04

Martin C. Martin


1 Answers

I'm not quite sure what you want, but it seems mygetter is supposed to be simply any object of type Getter. Use std::declval to obtain such an object without anything else (you can only use it for type deduction)

typedef decltype(std::declval<Getter>().get()) gotten_t;
like image 158
leftaroundabout Avatar answered Oct 04 '22 15:10

leftaroundabout