January 2020
Intermediate to advanced
454 pages
11h 25m
English
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. ...