c++ - Why is std::unique_lock not derived from std::lock_guard -


std::lock_guard , std::unique_lock interfaces similar, in common part (constructors , destructor).

why there no hierarchical relationship between them?

they have non substitutable semantics:
lock_guard guaranteed locked through of it's lifetime.
unique_lock doesn't guarantee doesn't follow "is a"-rule (unique_lock cannot lock_guard, offers fewer guarantees).

also implementing unique_lock based on lock_guard wouldn't trivial (maybe impossible) reason.

obviously same true other way round: although can implement lock_guard in terms of unique_lock (private inheritance), lock_guard doesn't provide same functionality (lock()/unlock()) unique_lock cannot publicly derived it.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -