Standard C ++ container and STL container in C ++

Recently, I am working on a C ++ project that is not allowed to use the standard template library or any other templates.

I am a little confused after doing some research. Which containers belong to the standard library, and others belong to the standard template library? Or we are not talking about the container for the standard library, are we?

Is the vector a container or not? Is the vector a class for the standard library or belongs to STL?

I hope to implement a list of some structure in the standard library, can I use a list or vector?

+7
c ++ stl c ++ - standard-library
source share
4 answers

Nothing in the C ++ standard library belongs to the STL. STL is another library that affects only many parts of the C ++ standard library. From the wiki tag:

[STL] is a C ++ library of common containers, iterators, algorithms, and function objects. When C ++ was standardized, large parts of the STL were accepted into the standard library , [...]

However, many people refer to the standard C ++ library as a standard template library, which is not entirely correct. I assume that if you are not allowed to use STL, they actually mean that you are forbidden to use the standard C ++ library. But you must ask them to find out what they really mean.

For more information, see What is the difference between "STL" and "C ++ Standard Library" ,

+9
source share

In my opinion, the difference between the STL and the C ++ standard library is somewhat similar to the relationship between Linux and GNU/Linux :

Historically, STL was the core (including containers, algorithms, and iterators, etc.), and the standard library is metaphorically a complete operating system built around the kernel that supplies everything else. The standard library made changes on top of the STL, but this part of the standard library has roots in the STL. (Remember how hard GNU people tried to remind us that Linux is just the kernel and insist on calling GNU / Linux?)

If the standard committee wrote the document instead of the C ++ standard, they probably would need to recognize the STL everywhere in the overlapping domain instead of requiring a distinction.

As stated in the comments in this answer , Bjarne Stroustrup, the inventor of C ++, described STL as

STL ("Library of standard templates", that is, containers and the algorithm of the standard library of ISO C ++ standards)

What is more, the main feature of STL, which was introduced into the standard library, is the concept according to which each STL algorithm must have a given algorithmic complexity of the worst case , which makes it an irrelevant question who implements STL. You only need to pay attention to the specification of the STL container or algorithm historically posted on the SGI website among other sources. This was quite important in prehistoric times, when everyone could come up with their own containers with different computational difficulties.

Other important STL functions introduced into the standard library include the new functional programming paradigm embodied in this <algorithm> and everywhere, which, in my opinion, enlivened C ++ as a language, complementing the traditional object-oriented programming paradigm.

In this sense, let’s return to your question, I consider it fair to say that containers, such as vector , belong to the STL (initially) and to the standard library.

+3
source share

In the early 90s there were no collection libraries in C ++. People either used RogueWave, Booch components, or something else, I forgot the name. That's why you see QList classes in QT because they need something.

At that time, SGI had a collection library that many on the standards committee saw and really loved. They founded a collection library that many people requested and called STL.

To date, I would say that the library component where the user explicitly creates the instance is part of the STL. To clarify, you, as a user of std :: vector, must indicate what it contains, i.e. std :: vector (1) this means that it is part of the STL. OTOH you do not need to instantiate fstream, even if it is a typedef of something like basic_fstream.

In terms of efficiency, STL is very meager and average, thanks to writers who are experts in areas such as specialization and TMP. Can I write what works best for my purpose. For a month I could write something that is 1% better for my needs, but is it worth it?

By the way, with the exception of OS calls and C calls, the entire C ++ template library, although (for example, fstream) you will never see it. Therefore, they prohibit most of the C ++ library.

(1) BTW I think the STL approach was the best. Other collections required you to do things such as output from the Collectible base class or something like that.

+2
source share

Thanks for all the answers to my question. Some own understanding of this problem: 1. When you need to develop without an STL or any other template library, you can only use a type library. You can use only a pointer, a string (possibly only a char) and a class in your program, which means you need to define your own data structure. 2. The purpose of using STL is to test your understanding of the basic C ++ operation, such as new / delete, pointer, and class. Another goal that I think of is to preserve memory. I encountered this problem during an interview. Hope this helps you if you come across the same case that I encountered before.

0
source share

All Articles