1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 #ifndef _LIBCPP___RANGES_OWNING_VIEW_H 10 #define _LIBCPP___RANGES_OWNING_VIEW_H 11 12 #include <__concepts/constructible.h> 13 #include <__concepts/movable.h> 14 #include <__config> 15 #include <__ranges/access.h> 16 #include <__ranges/concepts.h> 17 #include <__ranges/data.h> 18 #include <__ranges/empty.h> 19 #include <__ranges/enable_borrowed_range.h> 20 #include <__ranges/size.h> 21 #include <__ranges/view_interface.h> 22 #include <__utility/move.h> 23 #include <type_traits> 24 25 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 26 #pragma GCC system_header 27 #endif 28 29 _LIBCPP_BEGIN_NAMESPACE_STD 30 31 #if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 32 33 namespace ranges { 34 template<range _Rp> 35 requires movable<_Rp> && (!__is_std_initializer_list<remove_cvref_t<_Rp>>) 36 class owning_view : public view_interface<owning_view<_Rp>> { 37 _Rp __r_ = _Rp(); 38 39 public: 40 owning_view() requires default_initializable<_Rp> = default; 41 _LIBCPP_HIDE_FROM_ABI constexpr owning_view(_Rp&& __r) : __r_(_VSTD::move(__r)) {} 42 43 owning_view(owning_view&&) = default; 44 owning_view& operator=(owning_view&&) = default; 45 46 _LIBCPP_HIDE_FROM_ABI constexpr _Rp& base() & noexcept { return __r_; } 47 _LIBCPP_HIDE_FROM_ABI constexpr const _Rp& base() const& noexcept { return __r_; } 48 _LIBCPP_HIDE_FROM_ABI constexpr _Rp&& base() && noexcept { return _VSTD::move(__r_); } 49 _LIBCPP_HIDE_FROM_ABI constexpr const _Rp&& base() const&& noexcept { return _VSTD::move(__r_); } 50 51 _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Rp> begin() { return ranges::begin(__r_); } 52 _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Rp> end() { return ranges::end(__r_); } 53 _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const requires range<const _Rp> { return ranges::begin(__r_); } 54 _LIBCPP_HIDE_FROM_ABI constexpr auto end() const requires range<const _Rp> { return ranges::end(__r_); } 55 56 _LIBCPP_HIDE_FROM_ABI constexpr bool empty() requires requires { ranges::empty(__r_); } 57 { return ranges::empty(__r_); } 58 _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const requires requires { ranges::empty(__r_); } 59 { return ranges::empty(__r_); } 60 61 _LIBCPP_HIDE_FROM_ABI constexpr auto size() requires sized_range<_Rp> 62 { return ranges::size(__r_); } 63 _LIBCPP_HIDE_FROM_ABI constexpr auto size() const requires sized_range<const _Rp> 64 { return ranges::size(__r_); } 65 66 _LIBCPP_HIDE_FROM_ABI constexpr auto data() requires contiguous_range<_Rp> 67 { return ranges::data(__r_); } 68 _LIBCPP_HIDE_FROM_ABI constexpr auto data() const requires contiguous_range<const _Rp> 69 { return ranges::data(__r_); } 70 }; 71 72 template<class _Tp> 73 inline constexpr bool enable_borrowed_range<owning_view<_Tp>> = enable_borrowed_range<_Tp>; 74 75 } // namespace ranges 76 77 #endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 78 79 _LIBCPP_END_NAMESPACE_STD 80 81 #endif // _LIBCPP___RANGES_OWNING_VIEW_H 82