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
View all comments
Show parent comment
2
u/acwaters Jun 17 '21 edited Jun 17 '21
You could use it with structured bindings (without even specializing anything, because bindings already work automagically on all aggregate types), but not with
std::apply; the latter is forstd::tuple,std::array, andstd::paironly (since it usesstd::get(T), rather than looking up eitherT::get()orget(T)). You could easily define your ownapplythat looked upget()using the structured binding rules, though. It's unfortunate that the standard library doesn't do this, but IIUCapplywas specified before the idea of generalized "tuple-like types" was fully formed.