January 2020
Intermediate to advanced
454 pages
11h 25m
English
With our constructors in place, we will also need to provide the ability to manually add data to our container (for example, if we initially created our container using the default constructor).
To start, let's focus on the push_back() function that std::vector provides:
void push_back(const T &value) { m_v.push_back(value); std::sort(m_v.begin(), m_v.end(), compare_type()); std::cout << "1\n"; } void push_back(T &&value) { m_v.push_back(std::move(value)); std::sort(m_v.begin(), m_v.end(), compare_type()); std::cout << "2\n"; }
As shown in the preceding code snippet, the push_back() function has the same function signatures as the version std::vector provides, allowing us to simply forward the function call ...