I believe this is fixed in C ++ 14 (see library defect 2103).
As a DR, this fix should be considered a fix for C ++ 11, so some C ++ 11 implementations have already fixed it.
My question is, is there a way to get me noexcept use the default assignment operator without having to define it myself?
In order for the default assignment operator to be noexcept , you need to make your noexcept sub-objects move the assignment operators.
The most obvious portable way I can think of is to use a wrapper around std::vector , which makes the move be noexcept
template<typename T, typename A = std::allocator<T>> struct Vector : std::vector<T, A> { using vector::vector; Vector& operator=(Vector&& v) noexcept { static_cast<std::vector<T,A>&>(*this) = std::move(v); return *this; } Vector& operator=(const Vector&) = default; };
Another similar option is to define your own type of distributor using the DR 2013 fix and use it:
template<typename T> struct Allocator : std::allocator<T> { Allocator() = default; template<typename U> Allocator(const Allocator<U>&) { } using propagate_on_container_move_assignment = true_type; template<typename U> struct rebind { using other = Allocator<U>; }; }; template<typename T> using Vector = std::vector<T, Allocator<T>>;
Another option is to use a standard library implementation, such as GCC, which implements permission for DR 2013, and also makes the std::vector move assign assign noexcept for other types of allocators, when it is known that all instances of the allocator are compared equal.
Jonathan wakely
source share