template <typename T> struct get_real_type { typedef T type; };
template <typename T> struct get_real_type<T*> { typedef T type; };
template <typename T> struct get_real_type<T&> { typedef T type; };
template <class T>
int foo() {
return get_real_type<T>::type::N;
}
struct Bar {
static const int N=24;
};
#include <iostream>
using namespace std;
int main() {
cout << foo<Bar*>() << endl;
cout << foo<Bar&>() << endl;
cout << foo<Bar>() << endl;
}
Incidentally, this is also the basis for the implementation of std::remove_reference. Actually you'd be better of using std::remove_reference, for your own sanity.
No comments:
Post a Comment