FirefoxMetzger FirefoxMetzger - 6 months ago 24
C++ Question

What is the difference between standard library implementations in C++?

I am probably 'on the wood way' as we Germans say. (Proverb for going the wrong way)

C++ defines a standard library and this standard gets updated frequently in C++98, C++11, C+17 (correct me if I am wrong). I would assume that each compiler or OS defines its own implementation of this standard library.

So besides the obvious OS specific parts, what are the differences (if any) between these implementations of the standard library?

Are there 'variants' of the implementation for the same OS? And if so when would I want to bother which implementation is used?


Basically any definition of every container is implementation specific. The Standard only dictates the declaration and the expected behavior, the side effects, and the conditions.

Example from §21.4.2:

basic_string(const basic_string& str,
               size_type pos, size_type n = npos,
               const Allocator& a = Allocator()); 

Requires: pos <= str.size()

Throws: out_of_range if pos > str.size().

Effects: Constructs an object of class basic_string and determines the effective length rlen of the initial string value as the smaller of n and str.size() - pos, as indicated in Table 65.

As you can see, the Standard also says what the constructor of std::basic_string does, it doesn't say how it should be implemented. It also defines the signature that should be used. The actual implementation vary across compiler vendors - gcc and clang have different implementations, although they are for the same platform, but the constructor do the same thing.

You don't need to worry about the implementations (well, technically, you do - some implementations don't implement everything, but that's rare), as they all (should) do everything documented in the standard.