1

A mutex we use has a strange interface (weird casing for example). Having a specialization for std::unique_lock would help reduce the cognitive overhead of using this mutex.

I couldn't find anything in the standard that specifically allowed specializing std::unique_lock. Thinking about it, I don't see any downsides off the top of my head to allowing specializations of std::unique_lock. Can someone confirm that it is indeed unspecified by the standard (and thus undefined behavior following the quote here https://stackoverflow.com/a/8513497)?

If it is permitted, could someone point me to the section in the standard that says that?

AlienHoboken
  • 2,750
  • 20
  • 23
Curious
  • 20,870
  • 8
  • 61
  • 146

1 Answers1

3

You can specialize std::unique_lock for your own mutex type:

[namespace.std]/1

A program may add a template specialization for any standard library template to namespace std only if the declaration depends on a user-defined type and the specialization meets the standard library requirements for the original template and is not explicitly prohibited.

There is nothing in the section for std::unique_lock to explicitly prohibit specialization. Thus the general rule applies.

jonspaceharper
  • 4,207
  • 2
  • 22
  • 42
llllllllll
  • 16,169
  • 4
  • 31
  • 54