It was said to me that the standard template library is differently implemented by every compiler, is this correct?
How can computational complexity (both in time and space) be observed if (for instance) the set container is implemented with a linked list rather than a red-black tree?
Did I miss something?
First things first, you probably mean the C++ standard library, not STL. The STL was a library written before C++ was standardised that heavily influenced the C++ standard library.
Now, the C++ standard provides rules and definitions that an implementation should conform to. In particular, the standard library is described as various partial class definitions and function declarations and the properties that they should have. The implementation is free to implement the library in any way it chooses, as long as it meets exactly what the standard says. Here’s what the standard says about a conforming implementation (§1.4):
For example, to ensure the complexity of a
std::listimplementation is equal to that of a double-linked list, its member functions are given complexity requirements. For example, thestd::list::insertfunctions are given the following requirement (§23.3.5.4, emphasis added):This doesn’t necessarily mean that
std::listmust be implemented as a double-linked list. However, this is a common choice. An implementation must only act in such a way that the requirements are met (or that it appears that the requirements have been met; the as-if rule).