Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

c++ - Is std::string part of the STL?

(When I say STL, I'm talking about the template library that revolves around containers, iterators, algorithms and functors.)
This question came to mind after thinking that a std::string mostly behaves like a normal container, with begin and end functions (including iterator), a size function and the possibility to use all of those for normal STL algorithms that work on containers / ranges through their iterators (e.g. transform, sort, find, etc.).

At the same time, however, it is not a container itself, as it doesn't fit in picture of containers that store arbitary data. Also, it operates on the contained data mostly through member functions, like substr, find_first_of, etc., while true container don't do that and let the algorithms handle that.

Additionally, the cplusplus reference site and the C++ standard don't list std::string together with the real containers, but in a distinct category.
However, on SGI's STL site, basic_string (and consequently the string typedef) are mentioned with the other container and the basic_string reference site states that it belongs to the "containers" category.

Now my question is, is string actually part of the STL or is it a distinct library itself?
And if it belongs to the STL now, did it differ in the original STL developed by Stepanov?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No, not really. And yes, kind of.

There are varying definitions of "the STL", including:

  • The actual HP/SGI STL, the original library, parts of which the C++ Standard Library was based on. They included containers, iterators and algorithms. Strings were not a part of this.

  • The parts of the C++ Standard Library that were based on the SGI STL library: containers, iterators and algorithms. Still no strings.

  • All of the C++ Standard Library. This definition has absolutely no grounding in logic or reality though, if followed, std::string would be included.

Note that the actual STL has developed since C++ was standardised (some 13 years ago, remember), and they've backwards-adopted some of the stuff that went into the standard, like strings. This does not mean that they were originally there in 1998... but they are there now for "compatibility" reasons.


Summary

The STL was containers, algorithms and iterators.

Strings and streams were adopted for C++98, then backwards-adopted for the modern SGI STL.

Whether strings are "part of the STL" or not depends on whether you follow logic and reason, or call the standard library "STL".

Hope this helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...