c++ - Preventing compilation of a function (or part of) based on template parameter -


given class such as

template<typename t = void> class foo {     void baz()     {         // regardless of specialization         /* stuff if template specified (i.e. if not void) */         /* cannot handled if statement because not compile if t == void */         }     /* rest if class */ } 

how can let compiler know shouldn't compile section of function if t == void? tried doing if statement won't compile section of code uses << operator variable of type t (which wrong if t == void).

you can't use class template parameters sfinae member functions.

you can use dummy template argument member function following :

template<typename t = void> class foo {    public:    template <typename dummy = char>     void baz(typename std::enable_if< !std::is_same<t ,void>::value,                                   dummy>::type * = 0)     {         // ...     } }; 

see here


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -