Skip to content

Commit f4d06ff

Browse files
committed
implement cross-capacity comparison
remove extra line
1 parent f3c6002 commit f4d06ff

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

include/beman/inplace_vector/inplace_vector.hpp

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ struct inplace_vector_base : private storage::storage_for<T, N> {
284284
}
285285

286286
// [containers.sequences.inplace_vector.data], data access
287+
287288
constexpr T *data() noexcept { return storage_data(); }
288289
constexpr const T *data() const noexcept { return storage_data(); }
289290

@@ -398,11 +399,6 @@ struct inplace_vector_base : private storage::storage_for<T, N> {
398399
}
399400
}
400401

401-
constexpr friend bool operator==(const inplace_vector_base &x,
402-
const inplace_vector_base &y) {
403-
return x.size() == y.size() && std::ranges::equal(x, y);
404-
}
405-
406402
constexpr void swap(inplace_vector_base &x) noexcept(
407403
N == 0 || (std::is_nothrow_swappable_v<T> &&
408404
std::is_nothrow_move_constructible_v<T>))
@@ -420,20 +416,37 @@ struct inplace_vector_base : private storage::storage_for<T, N> {
420416
x.swap(y);
421417
}
422418

419+
// [inplace.vector.comparison], comparison
420+
421+
template <std::size_t M>
422+
constexpr friend bool operator==(const inplace_vector_base &x,
423+
const inplace_vector_base<T, M> &y) {
424+
const auto sz = std::min(x.size(), y.size());
425+
426+
return x.size() == y.size() &&
427+
std::ranges::equal(x.begin(), x.begin() + sz, y.begin(),
428+
y.begin() + sz);
429+
}
430+
431+
template <std::size_t M>
432+
requires std::three_way_comparable<T> || lessthan_comparable<T>
423433
constexpr friend auto operator<=>(const inplace_vector_base &x,
424-
const inplace_vector_base &y)
425-
requires(details::lessthan_comparable<T>)
426-
{
434+
const inplace_vector_base<T, M> &y) {
435+
using result_t = std::conditional_t<std::three_way_comparable<T>,
436+
std::compare_three_way_result<T>,
437+
std::strong_ordering>;
438+
427439
if constexpr (std::three_way_comparable<T>) {
428-
return std::lexicographical_compare_three_way(x.begin(), x.end(),
429-
y.begin(), y.end());
440+
return std::lexicographical_compare_three_way(
441+
x.begin(), x.end(), y.begin(), y.end(), std::compare_three_way());
430442
} else {
431443
const auto sz = std::min(x.size(), y.size());
444+
432445
for (std::size_t i = 0; i < sz; ++i) {
433446
if (x[i] < y[i])
434-
return std::strong_ordering::less;
447+
return result_t::less;
435448
if (y[i] < x[i])
436-
return std::strong_ordering::greater;
449+
return result_t::greater;
437450
// [container.opt.reqmts] < must be total ordering relationship
438451
}
439452

@@ -925,6 +938,8 @@ struct inplace_vector : public details::inplace_vector_base<T, N> {
925938

926939
} // namespace freestanding
927940

941+
// [inplace.vector.erasure], erasure
942+
928943
template <typename T, std::size_t N, typename U = T>
929944
constexpr std::size_t erase(details::inplace_vector_base<T, N> &c,
930945
const U &value) {

tests/beman/inplace_vector/compare.test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ TEST(Compare, threeway_uncomparable) {
330330

331331
// In accordance with P3698R0, we compare vectors with identical elements but
332332
// different capacities
333-
334333
TEST(Compare, threeway_cross_capacity_smaller) {
335334
vec_list<inplace_vector<int, 4>, inplace_vector<int, 5>> list{
336335
.empty{},

0 commit comments

Comments
 (0)