Question: ```
template <typename T>
class Test
{
};

class A : public X;

class B;

Test<A> a; // OK
Test<B> b; // NOT OK

```

I would like to accomplish something like this.

Maybe this can be accomplished more easily. Basically, what I need it for is this: the template class T should be able to lock a std::mutex member m\_mutex in an object of type T if it exists.

Answer: 
With a static assertion and the appropriate [type trait class](http://en.cppreference.com/w/cpp/types/is_base_of):

```
#include <type_traits>

template <typename T>
class Test
{
    static_assert( std::is_base_of<X,T>::value, "T doesn't derive from X!"); 
};

```

[**Live example**](http://coliru.stacked-crooked.com/a/e53bdc092bf59aee).
You can use [**`std::is_base_of<>`**](http://en.cppreference.com/w/cpp/types/is_base_of) with a SFINAE check:

```
template<
    typename T,
    typename = typename std::enable_if<std::is_base_of<X, T>::value>::type
>
class Test {
   ...
};

```