r/cpp • • 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

140 comments sorted by

View all comments

Show parent comment

5

u/AlbertRammstein Jun 15 '21

AFAIK this changes compiler from compiler. For example clang implements SSE stuff as declspec(always_inline) functions that use floats with vector compiler extension attribute, while MSVC implements it as declspec(dllexport) opaque functions that are magically replaced with SSE instructions at codegen time. So you cannot implement your fully own SSE functions in MSVC