Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
STL container for storing instances of any data type.
Prefer using a std::vector over an array [1][2][3][4]. You can also create 2-dimensional matrices(or more dimensions).
Advantages of a std::vector over an array are:
- std::vector allocates memory from the free space when increasing in size
- std::vector is not a pointer in disguise [3]
- std::vector can increase/decrease in size run-time
- std::vector can do range checking (using at())
Note that among these are also more general container code snippets.
- AllAboutEqual, check if all doubles in a std::vector are about equal
- Append two std::vectors, Append
- Append, append two std::vectors
- Check if all doubles in a std::vector are about equal, AllAboutEqual
- CreateVector, create a std::vector from three values
- Convert Matrix<X> to Matrix<Y>, ConvertMatrix
- Convert std::vector<std::vector<X> > to std::vector<std::vector<Y> >, ConvertMatrix
- Convert two 2D std::vector<X> to 2D std::vector<Y>, ConvertMatrix
- ConvertMatrix, convert Matrix<X> to Matrix<Y>
- ConvertMatrix, convert std::vector<std::vector<X> > to std::vector<std::vector<Y> >
- ConvertMatrix, convert two 2D std::vector<X> to 2D std::vector<Y>
- CoutVector, std::cout on a std::vector
- GetIncVector, get a std::vector of incremented values (for example with values 0,1,2,3,etc)
- HugeVector, class that can contain more elements than std::vector
- LoopReader, reading a container looped
- RandomShuffle, shuffle a std::vector to a random order
- Reading a container looped, LoopReader
- Save a container to file, SaveContainer
- SaveContainer, save a container to file
- Shuffle a std::vector to a random order, RandomShuffle
- Sort a std::vector, SortVector
- SortVector, sort a std::vector
- std::cout on a std::vector, CoutVector
External links
- Herb Sutter, Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. 2005. ISBN: 0-32-111358-6. Chapter 76: 'Use vector by default. Otherwise, choose an appropriate container'.
- Herb Sutter, Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. 2005. ISBN: 0-32-111358-6. Chapter 77: 'Use vector and string instead of arrays'.
- Marshall Cline, Greg Lomow and Mike Girou. C++ FAQs. ISBN: 0-201-3098301. FAQ 28.02: 'Are arrays good or evil?' (Answer: 'Arrays are evil').
- Bjarne Stroustrup. The C++ Programming Language (3rd edition). 1997. ISBN: 0-201-88954-4. Chapter C.14.11 'Prefer vector over array'.
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.
