From d4b9124b9fc4a154f11578c5e6ba68415c8ba0c9 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 4 Oct 2019 00:53:12 -0400 Subject: [PATCH] rstl: Allow move constructors and assignment operators to be conditionally noexcept Makes the constructors and assignment operators for reserved_vector noexcept, allowing them to play nicely with standard facilities and avoid needing to copy construct where avoidable. --- Runtime/rstl.hpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Runtime/rstl.hpp b/Runtime/rstl.hpp index 1817ddc45..39cd243eb 100644 --- a/Runtime/rstl.hpp +++ b/Runtime/rstl.hpp @@ -271,10 +271,10 @@ private: } public: - reserved_vector() : x0_size(0) {} + reserved_vector() noexcept(std::is_nothrow_constructible_v) : x0_size(0) {} template - reserved_vector(const T(&l)[LN]) + reserved_vector(const T (&l)[LN]) noexcept(std::is_nothrow_copy_constructible_v) : x0_size(LN) { static_assert(LN <= N, "initializer array too large for reserved_vector"); for (size_t i = 0; i < LN; ++i) { @@ -282,13 +282,14 @@ public: } } - reserved_vector(const reserved_vector& other) : x0_size(other.x0_size) { + reserved_vector(const reserved_vector& other) noexcept(std::is_nothrow_copy_constructible_v) + : x0_size(other.x0_size) { for (size_t i = 0; i < x0_size; ++i) { ::new (static_cast(std::addressof(_value(i)))) T(other._value(i)); } } - reserved_vector& operator=(const reserved_vector& other) { + reserved_vector& operator=(const reserved_vector& other) noexcept(std::is_nothrow_copy_assignable_v) { size_t i = 0; if (other.x0_size > x0_size) { for (; i < x0_size; ++i) { @@ -317,13 +318,14 @@ public: return *this; } - reserved_vector(reserved_vector&& other) : x0_size(other.x0_size) { + reserved_vector(reserved_vector&& other) noexcept(std::is_nothrow_move_constructible_v) : x0_size(other.x0_size) { for (size_t i = 0; i < x0_size; ++i) { ::new (static_cast(std::addressof(_value(i)))) T(std::forward(other._value(i))); } } - reserved_vector& operator=(reserved_vector&& other) { + reserved_vector& operator=(reserved_vector&& other) noexcept( + std::is_nothrow_move_assignable_v&& std::is_nothrow_move_constructible_v) { size_t i = 0; if (other.x0_size > x0_size) { for (; i < x0_size; ++i) {