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

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -