Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 936
FirefoxMetzger Avatar asked Sep 03 '16 18:09

FirefoxMetzger


2 Answers

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.

like image 60
Rakete1111 Avatar answered Nov 07 '22 06:11

Rakete1111


Well, the word standard does imply a certain meaning, doesn't it.

The point is: if things are standard, then each implementation needs to reflect that standard.

In other words: don't worry about standards, but about those things that are not exactly specified, like here for example.

Besides, this is a very wide topic. I think you should narrow it down to more specific questions/areas.

Edit - reasons why various groups create their own implementations:

  1. In contrast to Java for example, there isn't "the golden standards" implementation
  2. Compiler builders might want to fine tune libraries to their product (and may it just be about legal/licencing topics)
like image 29
GhostCat Avatar answered Nov 07 '22 05:11

GhostCat