Algorithms require move operators not to throw

All algorithms use std::swap and std::move when moving elements around, but only if the move-constructor and move-assignment are marked noexcept. Therefore, it is important to have these implemented for heavy objects when using algorithms. If they are not available and exception free, the elements will be copied instead.

Note that if you implement the move construction and move assignment in your class, std::swap will utilize them and, therefore, a specified std::swap overload is not needed.

Get C++ High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.