Consider the following code:
#include <iostream> #include <type_traits> #include <typeinfo> struct Base { int f() const; double f(); }; struct Derived : public Base { template <typename T = decltype(std::declval<Derived>().f())> // Modify this T g() const; }; int main() { const Derived x; std::cout<<typeid(decltype(xg())).name()<<std::endl; // Prints "d", not "i" return 0; }
How to change decltype(std::declval<Derived>().f()) so that it returns int , not double ?
I tried decltype(std::declval<const Derived>().f() , but it does not compile.
c ++ c ++ 11 const decltype
Vincent
source share