c++ - is_foo struct inside a templated class -
i have foo struct templated on size_t. want write is_foo struct such is_foo<t>::value true if , if t looks foo<n> n. here minimal example of issue:
template<typename t> class bar { public: template<size_t n> struct foo{}; template<typename> struct is_foo : std::false_type{}; template<size_t n> struct is_foo<foo<n>> : std::true_type{}; template<typename = std::enable_if<is_foo<foo<0>>::value>::type> bar(int x) {} }; my problem bar<double> b(5); in main fails compile, meaning is_foo<foo<0>>::value turned out false. however, if remove template<typename t> declaration of class bar, bar b(5) compile fine. how can make is_foo behave way want to?
my problem
bar<double> b(5);in main fails compile, meaningis_foo<foo<0>>::valueturned outfalse
not really.
+ g++ -std=c++14 -o2 -wall -pedantic -pthread main.cpp main.cpp:10:25: error: need 'typename' before 'std::enable_if<bar<t>::is_foo<bar<t>::foo<0ul> >::value>::type' because 'std::enable_if<bar<t>::is_foo<bar<t>::foo<0ul> >::value>' dependent scope template<typename = std::enable_if<is_foo<foo<0>>::value>::type> ^ [snip] + clang++ -std=c++14 -o2 -wall -pedantic -pthread main.cpp main.cpp:10:25: error: missing 'typename' prior dependent type name 'std::enable_if<is_foo<foo<0> >::value>::type' template<typename = std::enable_if<is_foo<foo<0>>::value>::type> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ typename
Comments
Post a Comment