Is the C++ standard library tied to the compiler or can a different implementation be provided?
I wonder about this mostly because it seems that the relation between the typeid keyword and std::type_info hinders this. The typeid keywords depends on the existence of std::type_info, which I would consider to be a dependency in the wrong direction. And I have no idea how a custom implementation should implement the type_info::name() method.
My questions are:
- Is the standard library replaceable?
- If yes, then how does one implement
std::type_info
Large parts of the library are independent of the compiler, like containers and algorithms.
Other parts are very much tied to a specific compiler, like you have found –
type_infowhere the library rather documents what the compiler does rather than prescribes it.Other similar examples might be bad_exception, std::size_t, and C++11 features like type_traits, atomics, and std::initializer_list, which all need support from the compiler. The library has to be closely matched to what a specific compiler actually does.
It is possible to write a library that works with several compilers, but not without tuning some low level code to each specific compiler. The libraries mentioned elsewhere does exactly that.