c++ - Can I restrict a test for a nested enum using SFINAE to a class without base classes? -
when use sfinae detect @ compile time if class has type, seems include derived types. ideally test existence of enum, shows same effect: both tests work in general, return true if class derives type or enum.
#include <iostream> struct { enum { istagged }; struct istaggedstruct{}; }; struct b :a {}; struct c {}; template< int > struct hastag; template< class tst > struct check { template< class t2 > static char (&test( ... ))[1]; template< class t2 > static char (&test( hastag<t2::istagged>* ))[2]; //template< class t2 > static char (&test( typename t2::istaggedstruct* ))[2]; static const bool value = sizeof(test<tst>(0))==sizeof(char[2]); }; int main(int argc, char* argv[]) { std::cout << "value a=" << check< >::value << std::endl; std::cout << "value b=" << check< b >::value << std::endl; std::cout << "value c=" << check< c >::value << std::endl; return 0; }
output:
+ g++ -std=c++03 main.cpp + ./a.out value a=1 value b=1 value c=0
wanted output a=1, rest 0. 1 test enum or type enabled @ time, of course. gcc c++03.
tl;dr: sfinae test if type exists in class true derived classes, how restrict class?
Comments
Post a Comment