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:
std::type_info
Yep, there are a variety of 'STLs':
Edit:
Since this apparently is about the C++ Standard Library , there are some alternatives to that too:
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_info
where 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.
It is replaceable. Take a look into stl port
Yes, STL is not binded with compiler even though different compile has it's default STL implementation. You can generally change the STL implemtation by change some Project setting.
Eg In vS2008, you can do
Tools->Options->Project and Solutions -> VC++ Directoires -> Include fiels, add a different implementation(eg STL PORT), then move this line to the top(above the default implementation), then you have it.
另一个替代STL的例子,牺牲了一些符合标准的速度:EASTL(电子艺界) https://github.com/paulhodge/EASTL
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.