Skip to Content
Advanced C++ Programming Cookbook
book

Advanced C++ Programming Cookbook

by Dr. Rian Quinn
January 2020
Intermediate to advanced
454 pages
11h 25m
English
Packt Publishing
Content preview from Advanced C++ Programming Cookbook

Adding elements to our container

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Modern C++ Programming Cookbook

Modern C++ Programming Cookbook

Marius Bancila

Publisher Resources

ISBN: 9781838559915Supplemental Content