KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've written the below code to try to detect if a type has a static member variable. Unfortunately, it's always returning that the variable does not exist. Could someone tell me where I'm going wrong? I'm using g++ 4.7.1. #include <iostream> #include <utility> #include <type_traits> using namespace std; template <class T> class has_is_baz { template<class U, typename std::enable_if<std::is_same<bool, decltype(U::is_baz)>::value>::type...> static std::true_type check(int); template <class> static std::false_type check(...); public: static constexpr bool value = decltype(check<T>(0))::value; }; struct foo { }; struct bar { static constexpr bool is_baz = true; }; int main() { cout << has_is_baz<foo>::value << '\n'; cout << has_is_baz<bar>::value << '\n'; }
Tags (comma-separated)
Save Edits
Cancel