From 58b3f51297a0ff240efa3c98cb90282cb1f64310 Mon Sep 17 00:00:00 2001 From: Paul Bowen-Huggett Date: Sat, 16 Dec 2023 12:18:58 +0100 Subject: [PATCH] Break an if statement in two to avoid a warning from MSVC. --- include/peejay/small_vector.hpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/include/peejay/small_vector.hpp b/include/peejay/small_vector.hpp index 0485da7..701b1b4 100644 --- a/include/peejay/small_vector.hpp +++ b/include/peejay/small_vector.hpp @@ -762,20 +762,21 @@ void small_vector:: constexpr auto idx = static_cast (Index); // Source and destination are both using the Index alternative and move-assign // is also nothrow, so we can move directly between them. - if (std::is_nothrow_move_assignable_v< - std::variant_alternative_t> && - arr_.index () == idx && rhs.arr_.index () == idx) { - std::get (arr_) = std::move (std::get (rhs.arr_)); - } else { - // Source and/or destination are not using the desired alternative. - static_assert (std::is_nothrow_default_constructible_v< - std::variant_alternative_t>, - "default ctor must be noexcept so that the variant cannot " - "become valueless"); - arr_.template emplace (); - std::move (std::begin (rhs), std::end (rhs), - std::back_inserter (std::get (arr_))); + if constexpr (std::is_nothrow_move_assignable_v< + std::variant_alternative_t>) { + if (arr_.index () == idx && rhs.arr_.index () == idx) { + std::get (arr_) = std::move (std::get (rhs.arr_)); + return; + } } + // Source and/or destination are not using the desired alternative. + static_assert (std::is_nothrow_default_constructible_v< + std::variant_alternative_t>, + "default ctor must be noexcept so that the variant cannot " + "become valueless"); + arr_.template emplace (); + std::move (std::begin (rhs), std::end (rhs), + std::back_inserter (std::get (arr_))); } template