In my understanding, standard library is a whole separate piece of software than a compiler is. In my opinion, they should be kept separate.
Advantages of this approach pretty much boil down to "they can evolve independently".
Disadvantage:
Some standard library features could be rewritten in more modern core language features to be more consistent. Sometimes it can lead to huge benefits aside from being consistent. Examples can be most of the algorithms in
<algorithm>
header when ranges arrive. And pretty much any template when concepts arrive.As standard library uses core language features, sometimes it might be hard to "synchronize them", to follow one pattern and not diverge. Also it could create a feature race, e.g. a feature from core language and a feature from standard library that do mostly the same thing might be rivaling each other to get into the standard. An example can be structured binding. Non declarations are not allowed to be a structured binding expression, because
std::tie()
does the same thing and it is considered that allowing non declaration binding would unnecessarily complicate things. To reach the conclusion, it required some research and time.Some features simply get into in a broken state (may be they were not broken prior to inclusion). An example can be I/O facilities. Now that core language has template parameter packs, it could be possible to write
printf()
like functions and have type safety as well. There is an implementation of it, called fmt (Disclaimer: I'm not affiliated with them in any way nor have I used it extensively). Also the synchronization with C I/O library is no longer needed.
There might be more, but those are the only ones that were on top of my head.
So, the question is: why standard comittee chose to slowly fuse standard library and core language? Why were not std::tuple<>
and std::initializer_list<>
(and some other features) added to the core language instead?
An example of fusing is (in)famous conversion to std::initializer_list<>
.
e.g.: auto indices{0, 1, 6, 9};
will result in std::initializer_list<int>
.
Also, structured binding:
for (const auto& [key, value]: map) {...}
will work even though std::pair
is a standard library feature.
std::pair
is required by the standard to be a struct with publicly accessible membersfirst
andsecond
, in that order. As such, it is required to be able to work with structured binding, without having to use theget/tuple_element
interface.