4

Does std::list<bool> have, by similar madness, an explicit specialisation like std::vector<bool>?

Is std::vector<bool> the only C++ Standard Library container to be thus afflicted?

Is there some kind of traits I can use to detect the specialisation?

Xavier Imbs
  • 212
  • 2
  • 10

1 Answers1

5

As seen in the standard, std::vector<bool> has it's own paragraph which dictates it's implementation. The requirement for std::list having one is not there, that doesn't mean an implementation is not allowed to not have one however. And as far as I know, std::vector is the only container that is required to have a specialization for bool.

Hatted Rooster
  • 35,759
  • 6
  • 62
  • 122
  • Thank you, I'll upvote this. But I guess if an implementation did have one then it would have to obey exactly the same rules as one which didn't have a specialisation? – Xavier Imbs Dec 08 '16 at 15:32
  • 1
    @XavierImbs Correct. – Hatted Rooster Dec 08 '16 at 15:32
  • 3
    @XavierImbs That's right, but the standard requirements mean an explicit specialisation of `std::list` would probably be useless. The standard requirements implicitly disallow packing multiple bits into a single byte. That's the reason why the requirements for `std::vector` are different from those for other `std::vector`s: it's specifically to allow such packing. –  Dec 08 '16 at 15:33