'c++ template: error expected type-specifier [duplicate]
I want to decltype the return type by the param 'c.data()'. Could you give me some ideas.
my env: gcc4.8.5,c11.
template <class T>
auto data(const T& c)
-> std::enable_if<std::is_convertible<decltype(c.data()), const char*>::type, const char*>::type {
return c.data();
}
Solution 1:[1]
You need to use typename to tell the compiler that std::enable_if<>::type is a type:
template <class T>
auto data(const T& c)
-> typename std::enable_if<std::is_convertible<decltype(c.data()), const char*>::type, const char*>::type {
return c.data();
}
It's worth noting that P0634 makes typename optional in C++20, which means your code is well-formed in C++20.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
