Skip to content

Commit

Permalink
Break an if statement in two to avoid a warning from MSVC.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhuggett committed Dec 16, 2023
1 parent 4b0e1bb commit 58b3f51
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions include/peejay/small_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,20 +762,21 @@ void small_vector<ElementType, BodyElements, Allocator>::
constexpr auto idx = static_cast<std::size_t> (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<idx, decltype (arr_)>> &&
arr_.index () == idx && rhs.arr_.index () == idx) {
std::get<idx> (arr_) = std::move (std::get<idx> (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<idx, decltype (arr_)>>,
"default ctor must be noexcept so that the variant cannot "
"become valueless");
arr_.template emplace<idx> ();
std::move (std::begin (rhs), std::end (rhs),
std::back_inserter (std::get<idx> (arr_)));
if constexpr (std::is_nothrow_move_assignable_v<
std::variant_alternative_t<idx, decltype (arr_)>>) {
if (arr_.index () == idx && rhs.arr_.index () == idx) {
std::get<idx> (arr_) = std::move (std::get<idx> (rhs.arr_));
return;

Check warning on line 769 in include/peejay/small_vector.hpp

View check run for this annotation

Codecov / codecov/patch

include/peejay/small_vector.hpp#L768-L769

Added lines #L768 - L769 were not covered by tests
}
}
// Source and/or destination are not using the desired alternative.
static_assert (std::is_nothrow_default_constructible_v<
std::variant_alternative_t<idx, decltype (arr_)>>,
"default ctor must be noexcept so that the variant cannot "
"become valueless");
arr_.template emplace<idx> ();
std::move (std::begin (rhs), std::end (rhs),
std::back_inserter (std::get<idx> (arr_)));
}

Check warning on line 780 in include/peejay/small_vector.hpp

View check run for this annotation

Codecov / codecov/patch

include/peejay/small_vector.hpp#L780

Added line #L780 was not covered by tests

template <typename ElementType, std::size_t BodyElements, typename Allocator>
Expand Down

0 comments on commit 58b3f51

Please sign in to comment.