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!");  }; 

live example.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -