diff --git a/libcxx/include/__iterator/concepts.h b/libcxx/include/__iterator/concepts.h --- a/libcxx/include/__iterator/concepts.h +++ b/libcxx/include/__iterator/concepts.h @@ -168,6 +168,10 @@ { _VSTD::to_address(__i) } -> same_as>>; }; + +template +concept __has_arrow = input_iterator<_Iter> && (is_pointer_v<_Iter> || requires(_Iter __i) { __i.operator->(); }); + // clang-format on #endif // !defined(_LIBCPP_HAS_NO_RANGES) diff --git a/libcxx/include/__iterator/iterator_traits.h b/libcxx/include/__iterator/iterator_traits.h --- a/libcxx/include/__iterator/iterator_traits.h +++ b/libcxx/include/__iterator/iterator_traits.h @@ -255,13 +255,13 @@ // Otherwise, if `decltype(declval().operator->())` is well-formed, then `pointer` names that // type. template -concept __has_arrow = +concept __has_arrow_op = requires(_Ip& __i) { __i.operator->(); }; template - requires __has_arrow<_Ip> && (!__has_member_pointer<_Ip>) + requires __has_arrow_op<_Ip> && (!__has_member_pointer<_Ip>) struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> { using type = decltype(declval<_Ip&>().operator->()); }; diff --git a/libcxx/include/__ranges/view.h b/libcxx/include/__ranges/view.h --- a/libcxx/include/__ranges/view.h +++ b/libcxx/include/__ranges/view.h @@ -40,6 +40,11 @@ default_initializable<_Tp> && enable_view<_Tp>; +template +concept __simple_view = + view<_Range> && range && + same_as, iterator_t> && + same_as, iterator_t>; } // end namespace ranges #endif // !_LIBCPP_HAS_NO_RANGES diff --git a/libcxx/include/concepts b/libcxx/include/concepts --- a/libcxx/include/concepts +++ b/libcxx/include/concepts @@ -442,6 +442,9 @@ template concept strict_weak_order = relation<_Rp, _Tp, _Up>; +template +concept __not_same_as = !same_as, remove_cvref_t<_Up>>; + #endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS) _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/test/libcxx/ranges/range.utility.helpers/has_arrow.compile.pass.cpp b/libcxx/test/libcxx/ranges/range.utility.helpers/has_arrow.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/ranges/range.utility.helpers/has_arrow.compile.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +#include + +#include "test_macros.h" + +struct simple_iter { + typedef std::input_iterator_tag iterator_category; + typedef int value_type; + typedef std::ptrdiff_t difference_type; + typedef int* pointer; + typedef int& reference; + + reference operator*() const; + pointer operator->() const; + friend bool operator==(const simple_iter&, const simple_iter&); + friend bool operator< (const simple_iter&, const simple_iter&); + friend bool operator<=(const simple_iter&, const simple_iter&); + friend bool operator> (const simple_iter&, const simple_iter&); + friend bool operator>=(const simple_iter&, const simple_iter&); + + simple_iter& operator++(); + simple_iter operator++(int); +}; + +struct no_star { + typedef std::input_iterator_tag iterator_category; + typedef int value_type; + typedef std::ptrdiff_t difference_type; + typedef int* pointer; + typedef int& reference; + + /* reference operator*() const; */ + pointer operator->() const; + friend bool operator==(const simple_iter&, const simple_iter&); + friend bool operator< (const simple_iter&, const simple_iter&); + friend bool operator<=(const simple_iter&, const simple_iter&); + friend bool operator> (const simple_iter&, const simple_iter&); + friend bool operator>=(const simple_iter&, const simple_iter&); + + simple_iter& operator++(); + simple_iter operator++(int); +}; + +struct no_arrow { + typedef std::input_iterator_tag iterator_category; + typedef int value_type; + typedef std::ptrdiff_t difference_type; + typedef int* pointer; + typedef int& reference; + + reference operator*() const; + /* pointer operator->() const; */ + friend bool operator==(const simple_iter&, const simple_iter&); + friend bool operator< (const simple_iter&, const simple_iter&); + friend bool operator<=(const simple_iter&, const simple_iter&); + friend bool operator> (const simple_iter&, const simple_iter&); + friend bool operator>=(const simple_iter&, const simple_iter&); + + simple_iter& operator++(); + simple_iter operator++(int); +}; + +struct E {}; +struct Incomplete; + +static_assert(std::__has_arrow); +static_assert(std::__has_arrow); +static_assert(!std::__has_arrow); +static_assert(std::__has_arrow); +static_assert(!std::__has_arrow); +static_assert(!std::__has_arrow); diff --git a/libcxx/test/libcxx/ranges/range.utility.helpers/not_same.compile.pass.cpp b/libcxx/test/libcxx/ranges/range.utility.helpers/not_same.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/ranges/range.utility.helpers/not_same.compile.pass.cpp @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +#include + +#include "test_macros.h" + +static_assert(std::__not_same_as); +static_assert(std::__not_same_as); +static_assert(!std::__not_same_as); +static_assert(!std::__not_same_as); +static_assert(!std::__not_same_as); +static_assert(!std::__not_same_as); +static_assert(!std::__not_same_as); diff --git a/libcxx/test/libcxx/ranges/range.utility.helpers/simple_view.compile.pass.cpp b/libcxx/test/libcxx/ranges/range.utility.helpers/simple_view.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/ranges/range.utility.helpers/simple_view.compile.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +#include + +#include "test_macros.h" + +struct SimpleView : std::ranges::view_base { + friend int* begin(SimpleView&); + friend int* begin(SimpleView const&); + friend int* end(SimpleView&); + friend int* end(SimpleView const&); +}; + +struct ConstableView : std::ranges::view_base { + friend int* begin(ConstableView&); + friend const int* begin(ConstableView const&); + friend int* end(ConstableView&); + friend const int* end(ConstableView const&); +}; + +struct NoConstView : std::ranges::view_base { + friend int* begin(NoConstView&); + friend int* end(NoConstView&); +}; + +struct DifferentSentinel : std::ranges::view_base { + struct sentinel { + friend bool operator==(int*, sentinel const&); + friend bool operator==(sentinel const&, int*); + }; + + friend int* begin(DifferentSentinel&); + friend int* begin(DifferentSentinel const&); + friend sentinel end(DifferentSentinel&); + friend sentinel end(DifferentSentinel const&); +}; + +static_assert( std::ranges::__simple_view); +static_assert(!std::ranges::__simple_view); +static_assert(!std::ranges::__simple_view); +static_assert(!std::ranges::__simple_view);