The std::unique_lock has a couple of constructors accepting a xxx_lock_t. These are empty structures:
struct adopt_lock_t {};
struct defer_lock_t {};
struct try_to_lock_t {};
And they are correspond to values as follows.
constexpr adopt_lock_t adopt_lock {};
constexpr defer_lock_t defer_lock {};
constexpr try_to_lock_t try_to_lock {};
Finally, here are std::unique_lock's constructors.
unique_lock (mutex_type& m, adopt_lock_t tag);
unique_lock (mutex_type& m, defer_lock_t tag) noexcept;
unique_lock (mutex_type& m, try_to_lock_t tag);
My question is:
Why they use this kind of tags instead of an enum type?
I think by using an enum we don't need to declare constructors per each type of locking. I also agree that by implementing each type's constructor, it doesn't need to compare which lock type is give in the implementation.
What are the main reasons?