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 when defining MyClass.

What I'm trying to do is: I create a cache that can use, as a key, everything that is returned by the recipient.

+6
source share
1 answer

I'm not quite sure what you want, but it seems that mygetter should just be any Getter object. Use std::declval to get such an object without anything else (you can use it only for type inference)

 typedef decltype(std::declval<Getter>().get()) gotten_t; 
+11
source

Source: https://habr.com/ru/post/913151/


All Articles