C++11 has very specific logic when user-defined types (UDTs) are used in standard library containers. Some containers use move assignment and move construction only if the move constructor does not throw exceptions or there is no copy constructor.
Let's see how we can ensure the compiler that the out class move_nothrow
has a non-throwing move
assignment operator and a non-throwing move
constructor.
Basic knowledge of C++11 rvalue references is required for this recipe. Knowledge of standard library containers will also serve you well.
Let's take a look at how we can improve our C++ classes using Boost.
- All we need to do is mark the
move_nothrow
assignment operator andmove_nothrow
constructor with theBOOST_NOEXCEPT
macro:
#include <boost/config.hpp> class move_nothrow { // Some class class members go here. // ... public: move_nothrow() BOOST_NOEXCEPT; move_nothrow...