Skip to content

Commit

Permalink
CI fixes and improvements
Browse files Browse the repository at this point in the history
Note the code is not yet conforming.
  • Loading branch information
mordante committed Jul 21, 2024
1 parent cd9e497 commit b2216ca
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 25 deletions.
13 changes: 4 additions & 9 deletions libcxx/include/__iterator/bounded_iter.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <__assert>
#include <__compare/ordering.h>
#include <__concepts/same_as.h>
#include <__compare/three_way_comparable.h>
#include <__config>
#include <__iterator/iterator_traits.h>
#include <__memory/pointer_traits.h>
Expand Down Expand Up @@ -226,15 +226,10 @@ struct __bounded_iter {
}

#if _LIBCPP_STD_VER >= 20
// It is not required that the underlying iterator supports operator<=>.
// Therefore this operator is only conditionally provided, which requires a
// templated function.
template <class _Tp = void>
requires requires(_Iterator const& __i) {
{ __i <=> __i } -> same_as<strong_ordering>;
}
_LIBCPP_HIDE_FROM_ABI constexpr friend strong_ordering
operator<=>(__bounded_iter const& __x, __bounded_iter const& __y) noexcept {
operator<=>(__bounded_iter const& __x, __bounded_iter const& __y) noexcept
requires three_way_comparable<__bounded_iter, strong_ordering>
{
return __x.__current_ <=> __y.__current_;
}
#endif // _LIBCPP_STD_VER >= 20
Expand Down
15 changes: 9 additions & 6 deletions libcxx/include/__iterator/wrap_iter.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define _LIBCPP___ITERATOR_WRAP_ITER_H

#include <__compare/ordering.h>
#include <__compare/three_way_comparable.h>
#include <__config>
#include <__iterator/iterator_traits.h>
#include <__memory/addressof.h>
Expand Down Expand Up @@ -120,8 +121,6 @@ operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX
return __x.base() == __y.base();
}

#if _LIBCPP_STD_VER <= 17

template <class _Iter1>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT {
Expand Down Expand Up @@ -182,21 +181,25 @@ operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX
return !(__y < __x);
}

#else // _LIBCPP_STD_VER <= 17
#if _LIBCPP_STD_VER >= 20

template <class _Iter1>
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering
operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) noexcept {
operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) noexcept
requires three_way_comparable<_Iter1, strong_ordering>
{
return __x.base() <=> __y.base();
}

template <class _Iter1, class _Iter2>
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering
operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept {
operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept
requires three_way_comparable_with<_Iter1, _Iter2, strong_ordering>
{
return __x.base() <=> __y.base();
}

#endif // _LIBCPP_STD_VER <= 17
#endif // _LIBCPP_STD_VER >= 20

template <class _Iter1, class _Iter2>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
Expand Down
11 changes: 7 additions & 4 deletions libcxx/include/deque
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ public:
return __x.__ptr_ == __y.__ptr_;
}

#if _LIBCPP_STD_VER <= 17
_LIBCPP_HIDE_FROM_ABI friend bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y) {
return !(__x == __y);
}
Expand All @@ -396,8 +395,12 @@ public:
_LIBCPP_HIDE_FROM_ABI friend bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y) {
return !(__x < __y);
}
#else // _LIBCPP_STD_VER <= 17
_LIBCPP_HIDE_FROM_ABI friend strong_ordering operator<=>(const __deque_iterator& __x, const __deque_iterator& __y) {

#if _LIBCPP_STD_VER >= 20
// template <class _Tp = void>
_LIBCPP_HIDE_FROM_ABI friend strong_ordering operator<=>(const __deque_iterator& __x, const __deque_iterator& __y)
requires three_way_comparable<pointer, strong_ordering>
{
if (__x.__m_iter_ < __y.__m_iter_)
return strong_ordering::less;

Expand All @@ -406,7 +409,7 @@ public:

return strong_ordering::greater;
}
#endif // _LIBCPP_STD_VER <= 17
#endif // _LIBCPP_STD_VER >= 20

private:
_LIBCPP_HIDE_FROM_ABI explicit __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT
Expand Down
4 changes: 2 additions & 2 deletions libcxx/test/std/containers/sequences/array/iterators.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
assert(r1 == std::strong_ordering::equal);

std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
std::same_as<std::strong_ordering> decltype(auto) r2 = cii <=> ii2;
assert(r2 == std::strong_ordering::equal);
# endif
}
Expand Down Expand Up @@ -204,7 +204,7 @@ TEST_CONSTEXPR_CXX17 bool tests()
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
assert(r1 == std::strong_ordering::equal);

std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
std::same_as<std::strong_ordering> decltype(auto) r2 = cii <=> ii2;
assert(r2 == std::strong_ordering::equal);
# endif
}
Expand Down
18 changes: 17 additions & 1 deletion libcxx/test/std/containers/sequences/deque/iterators.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,23 @@ int main(int, char**)
i = c.begin();
C::const_iterator j;
j = c.cbegin();

assert(i == j);
assert(!(i != j));

assert(!(i < j));
assert((i <= j));

assert(!(i > j));
assert((i >= j));

# if TEST_STD_VER >= 20
// P1614 + LWG3352
// When the allocator does not have operator<=> then neither does the iterator.
// Make sure to test with an allocator that does not have operator<=>.
static_assert(!std::three_way_comparable<min_allocator<int>, std::strong_ordering>);
static_assert(!std::three_way_comparable<typename C::iterator, std::strong_ordering>);
# endif
}
#endif
#if TEST_STD_VER > 11
Expand Down Expand Up @@ -80,7 +96,7 @@ int main(int, char**)
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
assert(r1 == std::strong_ordering::equal);

std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
std::same_as<std::strong_ordering> decltype(auto) r2 = cii <=> ii2;
assert(r2 == std::strong_ordering::equal);
# endif // TEST_STD_VER > 20
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,21 @@ TEST_CONSTEXPR_CXX20 bool tests()
C::iterator i = c.begin();
C::iterator j = c.end();
assert(std::distance(i, j) == 0);

assert(i == j);
assert(!(i != j));

assert(!(i < j));
assert((i <= j));

assert(!(i > j));
assert((i >= j));

# if TEST_STD_VER >= 20
// P1614 + LWG3352
std::same_as<std::strong_ordering> decltype(auto) r = i <=> j;
assert(r == std::strong_ordering::equal);
# endif
}
{
typedef bool T;
Expand All @@ -86,7 +100,21 @@ TEST_CONSTEXPR_CXX20 bool tests()
C::const_iterator i = c.begin();
C::const_iterator j = c.end();
assert(std::distance(i, j) == 0);

assert(i == j);
assert(!(i != j));

assert(!(i < j));
assert((i <= j));

assert(!(i > j));
assert((i >= j));

# if TEST_STD_VER >= 20
// P1614 + LWG3352
std::same_as<std::strong_ordering> decltype(auto) r = i <=> j;
assert(r == std::strong_ordering::equal);
# endif
}
{
typedef bool T;
Expand Down Expand Up @@ -137,7 +165,7 @@ TEST_CONSTEXPR_CXX20 bool tests()
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
assert(r1 == std::strong_ordering::equal);

std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
std::same_as<std::strong_ordering> decltype(auto) r2 = cii <=> ii2;
assert(r2 == std::strong_ordering::equal);
# endif // TEST_STD_VER > 20
}
Expand Down
34 changes: 33 additions & 1 deletion libcxx/test/std/containers/sequences/vector/iterators.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,23 @@ TEST_CONSTEXPR_CXX20 bool tests()
C::iterator i = c.begin();
C::iterator j = c.end();
assert(std::distance(i, j) == 0);

assert(i == j);
assert(!(i != j));

assert(!(i < j));
assert((i <= j));

assert(!(i > j));
assert((i >= j));

# if TEST_STD_VER >= 20
// P1614 + LWG3352
// When the allocator does not have operator<=> then neither does the iterator.
// Make sure to test with an allocator that does not have operator<=>.
static_assert(!std::three_way_comparable<min_allocator<int>, std::strong_ordering>);
static_assert(!std::three_way_comparable<typename C::iterator, std::strong_ordering>);
# endif
}
{
typedef int T;
Expand All @@ -96,7 +112,23 @@ TEST_CONSTEXPR_CXX20 bool tests()
C::const_iterator i = c.begin();
C::const_iterator j = c.end();
assert(std::distance(i, j) == 0);

assert(i == j);
assert(!(i != j));

assert(!(i < j));
assert((i <= j));

assert(!(i > j));
assert((i >= j));

# if TEST_STD_VER >= 20
// P1614 + LWG3352
// When the allocator does not have operator<=> then neither does the iterator.
// Make sure to test with an allocator that does not have operator<=>.
static_assert(!std::three_way_comparable<min_allocator<int>, std::strong_ordering>);
static_assert(!std::three_way_comparable<typename C::iterator, std::strong_ordering>);
# endif
}
{
typedef int T;
Expand Down Expand Up @@ -169,7 +201,7 @@ TEST_CONSTEXPR_CXX20 bool tests()
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
assert(r1 == std::strong_ordering::equal);

std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
std::same_as<std::strong_ordering> decltype(auto) r2 = cii <=> ii2;
assert(r2 == std::strong_ordering::equal);
# endif // TEST_STD_VER > 20
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ TEST_CONSTEXPR void test_type() {
std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
assert(r1 == std::strong_ordering::equal);

std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2;
#ifdef __cpp_lib_ranges_as_const
std::same_as<std::strong_ordering> decltype(auto) r2 = cii <=> ii2;
assert(r2 == std::strong_ordering::equal);
#endif
}

TEST_CONSTEXPR bool test() {
Expand Down

0 comments on commit b2216ca

Please sign in to comment.