Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ STL containers

Different STL containers like vector, stack, set, queue, etc support different access methods on them.

If you are coding for example in Notepad++ or vim, you have to continuously refer to the documentation to see what all methods are available, atleast I have to.

Is there some good way of remembering which container supports which methods??

like image 317
Moeb Avatar asked Apr 12 '10 16:04

Moeb


People also ask

What is an STL container?

An STL container is a collection of objects of the same type (the elements). Container owns the elements. Creation and destruction is controlled by the container.

How many containers are there in STL?

In C++, there are generally 3 kinds of STL containers: Sequential Containers. Associative Containers. Unordered Associative Containers.

What is a container in C?

A container is an object that stores a collection of elements (i.e. other objects). Each of these containers manages the storage space for their elements and provides access to each element through iterators and/or member functions.

Is there any STL in C?

C can't have an "exact equivalent" of STL because C doesn't have templates or classes.


3 Answers

The names of the methods aren't different for the sake of being different. It helps in remembering which containers have which methods, to understand the meaning of the name. push_back for example is nonsensical in relation to sets. insert doesn't make any sense when talking about stacks (of course stacks don't have a front or a back either, so it doesn't support push_back, just push). For a vector, both have a well-defined meaning, so vector supports both insert and push_back.

like image 190
Eclipse Avatar answered Nov 07 '22 00:11

Eclipse


Use them enough so that you remember the methods of each.

like image 37
Ben S Avatar answered Nov 07 '22 00:11

Ben S


If your memory keeps failing you, try keeping a reference of them all up in another window. If you have more than one monitor, it's really handy to have stuff like this on a second monitor (for documentation of any kind).

Alternatively I highly recommend a real coding IDE with intellisense! Notepad++ is probably too simple for being productive in C++.

like image 29
AshleysBrain Avatar answered Nov 07 '22 01:11

AshleysBrain