Skip to content
Merged
Show file tree
Hide file tree
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
44 changes: 24 additions & 20 deletions include/beman/inplace_vector/inplace_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ Software.
*/
#include <algorithm> // for rotate...
#include <array>
#include <compare>
#include <concepts> // for lots...
#include <cstddef> // for size_t
#include <cstdint> // for fixed-width integer types
Expand Down Expand Up @@ -309,6 +310,11 @@ concept container_compatible_range =
template <typename T, std::size_t N>
concept satify_constexpr = N == 0 || std::is_trivial_v<T>;

template <typename T>
concept lessthan_comparable = requires(const T &a, const T &b) {
{ a < b } -> std::convertible_to<bool>;
};

} // namespace beman::details::inplace_vector

// Types implementing the `inplace_vector`'s storage
Expand Down Expand Up @@ -1001,27 +1007,25 @@ struct inplace_vector
insert_range(begin(), il);
}

constexpr friend int /*synth-three-way-result<T>*/
operator<=>(const inplace_vector & x, const inplace_vector & y) {
if (x.size() < y.size())
return -1;
if (x.size() > y.size())
return +1;

bool all_equal = true;
bool all_less = true;
for (size_type i = 0; i < x.size(); ++i) {
if (x[i] < y[i])
all_equal = false;
if (x[i] == y[i])
all_less = false;
constexpr friend auto operator<=>(const inplace_vector &x,
const inplace_vector &y)
requires(beman::details::inplace_vector::lessthan_comparable<T>)
{
if constexpr (std::three_way_comparable<T>) {
return std::lexicographical_compare_three_way(x.begin(), x.end(),
y.begin(), y.end());
} else {
const auto sz = std::min(x.size(), y.size());
for (std::size_t i = 0; i < sz; ++i) {
if (x[i] < y[i])
return std::strong_ordering::less;
if (y[i] < x[i])
return std::strong_ordering::greater;
// [container.opt.reqmts] < must be total ordering relationship
}

return x.size() <=> y.size();
}

if (all_equal)
return 0;
if (all_less)
return -1;
return 1;
}
};

Expand Down
1 change: 1 addition & 0 deletions tests/beman/inplace_vector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ endfunction()
# Tests for official specs
add_gtest(container_requirements)
add_gtest(triviality)
add_gtest(compare)
add_gtest(constructors)
add_gtest(size_n_data)
add_gtest(erasure)
Expand Down
Loading