File indexing completed on 2026-05-03 08:13:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___CXX03___RANGES_REF_VIEW_H
0011 #define _LIBCPP___CXX03___RANGES_REF_VIEW_H
0012
0013 #include <__cxx03/__concepts/convertible_to.h>
0014 #include <__cxx03/__concepts/different_from.h>
0015 #include <__cxx03/__config>
0016 #include <__cxx03/__iterator/concepts.h>
0017 #include <__cxx03/__iterator/incrementable_traits.h>
0018 #include <__cxx03/__iterator/iterator_traits.h>
0019 #include <__cxx03/__memory/addressof.h>
0020 #include <__cxx03/__ranges/access.h>
0021 #include <__cxx03/__ranges/concepts.h>
0022 #include <__cxx03/__ranges/data.h>
0023 #include <__cxx03/__ranges/empty.h>
0024 #include <__cxx03/__ranges/enable_borrowed_range.h>
0025 #include <__cxx03/__ranges/size.h>
0026 #include <__cxx03/__ranges/view_interface.h>
0027 #include <__cxx03/__type_traits/is_object.h>
0028 #include <__cxx03/__utility/declval.h>
0029 #include <__cxx03/__utility/forward.h>
0030
0031 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0032 # pragma GCC system_header
0033 #endif
0034
0035 _LIBCPP_BEGIN_NAMESPACE_STD
0036
0037 #if _LIBCPP_STD_VER >= 20
0038
0039 namespace ranges {
0040 template <range _Range>
0041 requires is_object_v<_Range>
0042 class ref_view : public view_interface<ref_view<_Range>> {
0043 _Range* __range_;
0044
0045 static void __fun(_Range&);
0046 static void __fun(_Range&&) = delete;
0047
0048 public:
0049 template <class _Tp>
0050 requires __different_from<_Tp, ref_view> && convertible_to<_Tp, _Range&> && requires { __fun(std::declval<_Tp>()); }
0051 _LIBCPP_HIDE_FROM_ABI constexpr ref_view(_Tp&& __t)
0052 : __range_(std::addressof(static_cast<_Range&>(std::forward<_Tp>(__t)))) {}
0053
0054 _LIBCPP_HIDE_FROM_ABI constexpr _Range& base() const { return *__range_; }
0055
0056 _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Range> begin() const { return ranges::begin(*__range_); }
0057 _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Range> end() const { return ranges::end(*__range_); }
0058
0059 _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const
0060 requires requires { ranges::empty(*__range_); }
0061 {
0062 return ranges::empty(*__range_);
0063 }
0064
0065 _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
0066 requires sized_range<_Range>
0067 {
0068 return ranges::size(*__range_);
0069 }
0070
0071 _LIBCPP_HIDE_FROM_ABI constexpr auto data() const
0072 requires contiguous_range<_Range>
0073 {
0074 return ranges::data(*__range_);
0075 }
0076 };
0077
0078 template <class _Range>
0079 ref_view(_Range&) -> ref_view<_Range>;
0080
0081 template <class _Tp>
0082 inline constexpr bool enable_borrowed_range<ref_view<_Tp>> = true;
0083 }
0084
0085 #endif
0086
0087 _LIBCPP_END_NAMESPACE_STD
0088
0089 #endif