I was wondering if there is a way for implementing the C++11 operator decltype using just C++98 features.
I mean something like
template<class Func>
struct decl_type{
typedef Func() type;
};
Obviously, my code does not compile.
You can't really implement the decltype since it is not really a function, but a compiler keyword, as you can't implement, for example, return or auto. Actually, decltype(...), somewhat similarly to auto, is replaced with the result typename by the c++ preprocessor, because, unlike, for example, Haskell or Javascript, you cannot have a type itself stored in a value. But you can overload a function multiple times, so you have something like
void declt(int a) {
typedef int type;
}
void declt(char a) {
typedef char type;
}
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With