Standard Library Containers, Algorithms, and Iterators
The C++ standard library has evolved a lot with C++11, C++14, C++17, and now C++20. However, at its core initially sat three main pillars: containers, algorithms, and iterators. They are all implemented as general-purpose classes or function templates. In this chapter, we'll look at how these can be employed together for achieving various goals.
We will cover the following recipes in this chapter:
- Using vector as a default container
- Using bitset for fixed-size sequences of bits
- Using
vector<bool>
for variable-size sequences of bits - Using the bit manipulation utilities
- Finding elements in a range
- Sorting a range
- Initializing a range
- Using set operations on a range
- Using iterators to insert new elements into a container
- Writing your own random-access iterator
- Container access with non-member functions
We'll begin this chapter by exploring...