example1_basic_usage.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include <iostream>
#include <type_traits>
#include <utility>

class NonDefaultConstructible {
public:
    NonDefaultConstructible(int) {}
    int getValue() const { return 42; }
};

int main() {
    using T = decltype(std::declval<NonDefaultConstructible>().getValue());
    std::cout << "The return type of getValue() is " 
              << (std::is_same<T, int>::value ? "int" : "not int") << std::endl;
    return 0;
}
Back to std_declval