Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small_vector CTAD / eliminate transfer_from_same() #50

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions include/peejay/small_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,19 +387,6 @@ class small_vector {
template <std::size_t Index, typename OtherVector>
void transfer_alternative_from (OtherVector &&rhs);

template <std::size_t Index, std::size_t OtherSize>
void transfer_from_same (small_vector<ElementType, OtherSize> const &rhs) {
std::get<Index> (arr_) = std::get<Index> (rhs.arr_);
}
template <std::size_t Index, std::size_t OtherSize>
void
transfer_from_same (small_vector<ElementType, OtherSize> &&rhs) noexcept (
std::is_rvalue_reference_v<decltype (rhs)>
&&std::is_nothrow_move_assignable_v<
std::variant_alternative_t<Index, decltype (arr_)>>) {
std::get<Index> (arr_) = std::move (std::get<Index> (rhs.arr_));
}

template <std::size_t OtherSize>
void transfer_from_different (
small_vector<ElementType, OtherSize> const &rhs) {
Expand Down Expand Up @@ -448,6 +435,9 @@ class small_vector {
large_type &to_large ();
};

template <typename ElementType>
small_vector (ElementType) -> small_vector<ElementType>;

// (ctor)
// ~~~~~~
template <typename ElementType, std::size_t BodyElements, typename Allocator>
Expand Down Expand Up @@ -719,7 +709,11 @@ void small_vector<ElementType, BodyElements,
// Source and destination are both using the desired alternative, so we can
// copy/move directly between them.
if (arr_.index () == Index && rhs.arr_.index () == Index) {
this->transfer_from_same<Index> (std::forward<OtherVector> (rhs));
if constexpr (std::is_rvalue_reference_v<decltype (rhs)>) {
std::get<Index> (arr_) = std::move (std::get<Index> (rhs.arr_));
} else {
std::get<Index> (arr_) = std::get<Index> (rhs.arr_);
}
} else {
// Source and/or destination are not using the desired alternative.
static_assert (std::is_nothrow_default_constructible_v<
Expand Down
Loading