c++ - How to allow template class instantiation only if the type T derives from type X? -
template <typename t> class test { }; class : public x; class b; test<a> a; // ok test<b> b; // not ok
i accomplish this.
maybe can accomplished more easily. basically, need this: template class t should able lock std::mutex member m_mutex in object of type t if exists.
with static assertion , appropriate type trait class:
#include <type_traits> template <typename t> class test { static_assert( std::is_base_of<x,t>::value, "t doesn't derive x!"); };
Comments
Post a Comment