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

Copy/move constructors

To support the ability to copy and move our container, we will need to implement a copy and move constructor as follows:

    container(        const container &other,        const Allocator &alloc    ) :        m_v(other.m_v, alloc)    {        std::cout << "5\n";    }    container(        container &&other    ) noexcept :        m_v(std::move(other.m_v))    {        std::cout << "6\n";    }

Since our custom wrapper container must always remain in sorted order, copying or moving one container to another doesn't change the order of the elements in the container, meaning that no sort operation is needed for these constructors either. We do, however, take special care to ensure that a copy and a move occur properly by copying or moving the internal std::vector that our container encapsulates. ...

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