-
Since c++11 the STL has std::array which is a template-based array class, use std::array instead of raw arrays whenever possible.
-
Something new about iterators:
begin() and end(): iterator
cbegin() and cend(): const_iterator
rbegin() and rend(): reverse_iterator
crbegin() and crend(): const_reverse_iterator -
Whenever you put scope resolution operator in the front of something, that means global scope
eg. ::toupper() -
std::array (c++ 11)
Fixed size
Direct element access
Provides access to the underlying raw array
Use instead of raw arrays when possible
All iterators available and do not invalidate -
eg: vec.emplace_back("Larry", 18);
//vec.push_back(Person{"Larry", 18});
emplace_back is really efficient, no move no copies, it just puts it right where it's supposed to be. -
std::back_inserter constructs a back-insert iterator that inserts new elements at the end of the container it applied to.
It's a special output iterator, awesome and efficient.
eg. std::copy(vec1.begin(), vec1.end(), std::back_inserter(vec2)); -
deque: double end queue, dynamic size, not contiguous in memory.
When adding new elements, it allocates blocks in the memory, as is shown in the picture below: -
std::list
doubly linked list of elements, no direct access, rapid insertion and deletion of element anywhere (const time) -
c++11
std::forward_list
Compare to list, reverse iterator not available, No size() and back() method.