diff --git a/libcxx/test/std/ranges/range.access/range.prim/empty.pass.cpp b/libcxx/test/std/ranges/range.access/range.prim/empty.pass.cpp --- a/libcxx/test/std/ranges/range.access/range.prim/empty.pass.cpp +++ b/libcxx/test/std/ranges/range.access/range.prim/empty.pass.cpp @@ -46,7 +46,7 @@ struct BadReturnType { BadReturnType empty() { return {}; } }; -static_assert(!std::is_invocable_v); +static_assert(!std::is_invocable_v); struct BoolConvertible { constexpr operator bool() noexcept(false) { return true; } @@ -54,7 +54,6 @@ struct BoolConvertibleReturnType { constexpr BoolConvertible empty() noexcept { return {}; } }; - static_assert(!noexcept(std::ranges::empty(BoolConvertibleReturnType()))); constexpr bool testEmptyMember() { @@ -91,79 +90,40 @@ return true; } -struct other_forward_iterator : forward_iterator { }; - -struct sentinel { - constexpr bool operator==(std::input_or_output_iterator auto) const { return true; } -}; - struct BeginEndNotSizedSentinel { - friend constexpr forward_iterator begin(BeginEndNotSizedSentinel) { return {}; } - friend constexpr sentinel end(BeginEndNotSizedSentinel) { return {}; } -}; -static_assert(!std::is_invocable_v); - -struct InvalidMinusBeginEnd { - friend constexpr random_access_iterator begin(InvalidMinusBeginEnd) { return {}; } - friend constexpr sentinel end(InvalidMinusBeginEnd) { return {}; } -}; - -// Int is integer-like, but it is not other_forward_iterator's difference_type. -constexpr short operator-(sentinel, random_access_iterator) { return 2; } -constexpr short operator-(random_access_iterator, sentinel) { return 2; } -static_assert(!std::is_invocable_v); - -// This type will use ranges::size. -struct IntPtrBeginAndEnd { - int buff[8]; - constexpr int* begin() { return buff; } - constexpr int* end() { return buff + 8; } + constexpr int *begin() const { return nullptr; } + constexpr auto end() const { return sentinel_wrapper(nullptr); } }; -static_assert(std::is_invocable_v); +static_assert( std::ranges::forward_range); +static_assert(!std::ranges::sized_range); -// size is disabled here, and it isn't sized_sentinel_for, so we have to compare begin -// and end again. +// size is disabled here, so we have to compare begin and end. struct DisabledSizeRangeWithBeginEnd { - friend constexpr forward_iterator begin(DisabledSizeRangeWithBeginEnd) { return {}; } - friend constexpr sentinel end(DisabledSizeRangeWithBeginEnd) { return {}; } - constexpr size_t size() const { return 1; } + constexpr int *begin() const { return {}; } + constexpr sentinel_wrapper end() const { return {}; } + size_t size() const; }; - -template <> +template<> inline constexpr bool std::ranges::disable_sized_range = true; -static_assert(!std::is_invocable_v); +static_assert(std::ranges::contiguous_range); +static_assert(!std::ranges::sized_range); struct BeginEndAndEmpty { - int* begin(); - int* end(); - constexpr bool empty() { return true; } -}; - -struct BeginEndAndConstEmpty { - int* begin(); - int* end(); - constexpr bool empty() const { return true; } + constexpr int *begin() const { return nullptr; } + constexpr int *end() const { return nullptr; } + constexpr bool empty() { return false; } }; constexpr bool testBeginEqualsEnd() { BeginEndNotSizedSentinel a; assert(std::ranges::empty(a) == true); - InvalidMinusBeginEnd b; - assert(std::ranges::empty(b) == true); - - IntPtrBeginAndEnd c; - assert(std::ranges::empty(c) == false); - DisabledSizeRangeWithBeginEnd d; assert(std::ranges::empty(d) == true); BeginEndAndEmpty e; - assert(std::ranges::empty(e) == true); - - BeginEndAndConstEmpty f; - assert(std::ranges::empty(f) == true); - assert(std::ranges::empty(std::as_const(f)) == true); + assert(std::ranges::empty(e) == false); // using begin()==end() + assert(std::ranges::empty(std::as_const(e)) == true); // using empty() return true; }