Note. I answered the actual question, not the headline.
Well, now hybird_lock<0> and hybird_lock<1> are completely different, one comes from std::mutex , and the other contains / wraps it. This changes the overall value of hybird_lock and the value behind it. That is, they are not semantically the same. This can lead to some rather unexpected consequences - hybird_lock<0> inherits a lot of things, which would not be in other cases.
If this were the only difference, I would not have started specializing at all. Remember that a null register will be known at compile time, and however that may be, the whole loop will be fully optimized.
If there were other important (or actual) optimizations, I would go for something like:
template<> class hybrid_lock<0> { public: void lock(){ this->mMutex.lock(); } void unlock(){ this->mMutex.unlock(); } private: std::mutex mMutex; };
This implementation makes 0 special case, and not something completely different.
luk32 source share