これは C++14 で修正されていると思います (ライブラリの欠陥 2103 を参照)。
DR として、その修正は C++11 の修正と見なされる必要があるため、一部の C++11 実装では既に修正されています。
私の質問は、noexcept
自分で定義せずにデフォルトの移動代入代入演算子を強制する方法はありますか?
デフォルトの移動代入演算子を使用noexcept
するには、そのサブオブジェクトに移動代入演算子を持たせる必要がありますnoexcept
。
私が考えることができる最も明白なポータブルな方法はstd::vector
、移動を強制するラッパーを使用することです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;
};
もう 1 つの同様のオプションは、DR 2013 修正プログラムを使用して独自のアロケーター タイプを定義し、それを使用することです。
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>>;
もう 1 つのオプションは、DR 2013 への解決を実装する GCC などの標準ライブラリ実装を使用することです。また、すべてのアロケーター インスタンスが等しいことがわかっている場合は、他のアロケーター タイプに対してstd::vector
の移動代入演算子を作成します。noexcept