r/cpp • u/Mateuszz88 • Jun 15 '21
Which std:: classes are magic?
Hi.
I am wondering: which classes in C++ get special powers granted by The Standard that are not available to mere user-defined classes?
What comes to my mind:
`std::initializer_list` because it is created anywhere with `{}`
possibly `std::type_info`, because it is only created by `typeid` and with no ctor
`std::source_location` when used as default parameter in function points to invocation place and not declaration place.
What else should be on this list? What shouldn't?
222
Upvotes
4
u/LuisAyuso Jun 15 '21
I do have a problem with the decision of allowing enum class constructor from integral values to facilitate this one type constructor. From that point on, I can silently construct off-range enums for any other enum class, which in my opinion defeats the purpose of strongly typed enums.
I do wish that std::bye would have been a magic type and leave other semantics untouched.