C ++ STL Containers

Various STL containers such as vector , stack , set , queue , etc. support different methods of access to them.

If you code, for example, in Notepad ++ or vim , you should constantly refer to the documentation to find out which all methods are available, at least I need.

Is there a good way to remember which container supports which methods?

+7
c ++ methods stl containers
source share
8 answers

Method names do not differ in order to be different. This helps to remember which containers have which methods to understand the meaning of the name. push_back for example, is meaningless in relation to a set. insert makes no sense to talk about stacks (of course, stacks don't have front or back, so it doesn't support push_back , just push ). For a vector, both have a well-defined meaning, so the vector supports both insert and push_back .

+12
source share

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

+5
source share

If your memory continues to fail, try saving the link to all of them to another window. If you have more than one monitor, it is very convenient to have such things on the second monitor (for documentation of any type).

As an alternative, I highly recommend a true IDE encoding with intellisense! Notepad ++ is probably too simple to be productive in C ++.

+4
source share

Use what was built into intellisense, such as Visual Studio on Windows or KDevelop on Linux.

There are also add-ons for vim and emacs for intellisense.

+3
source share

Even if you remember all the β€œmethods”, this is only one part of the story. To use STL effectively, you also need to know the algorithms. I would suggest reading about STL in a good book (Stroustrup, Josuttis, ...) to just remember what is available, and then return to books or open a link site when you need the exact syntax.

+3
source share

This is not exactly what you are looking for, but Scott Meyers (from Effective C ++ Glory) compiled the following list of STL algorithms based on Nikolai Josutt's book, The C ++ Standard Library:

Josuttis STL Algorithm Summary

+1
source share

Find out what these are and the general methods, and then it's pretty easy to remember which ones apply. STL is not entirely consistent, but it is pretty good.

+1
source share

Recognizing that it does not support memorization, you can get some kind of intellisense running on vim. The advantage is that you can create tags from your own and external source code files. In any case, STL needs special treatment, which is described here.

Download these vim scripts OmniCppComplete and SuperTab .

Install OmniCppComplete:

  • Unzip the plugin to ~ / .vim.

Install SuperTab:

  • Open the file in vim ($ vim supertab.vba).
  • File Source (: so%).

Install ctags through your favorite package manager. Download and unzip this file and run ctags.

 $ ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ tags_stl cpp_src 

This will create a ctags file called 'tags_stl' containing the STL tags. Copy it anywhere. Add the following lines that do not yet exist in ~ / .vimrc:

 set tags+=~/path/to/your/tags_stl filetype on filetype plugin on let OmniCpp_GlobalScopeSearch=1 let OmniCpp_NamespaceSearch=2 let OmniCpp_MayCompleteDot=1 let OmniCpp_MayCompleteArrow=1 let OmniCpp_MayCompleteScope=1 let OmniCpp_DisplayMode=1 let OmniCpp_DefaultNamespaces=["std"] 

This completes the STL statements in 'tab', '.', '::' and '->', even when 'using namespace std;'. Do not do this if you hate the purple color.

+1
source share

All Articles