Path: blob/main/contrib/llvm-project/libcxx/include/__ranges/owning_view.h
35235 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___RANGES_OWNING_VIEW_H10#define _LIBCPP___RANGES_OWNING_VIEW_H1112#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 <__type_traits/remove_cvref.h>23#include <__utility/move.h>2425#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)26# pragma GCC system_header27#endif2829_LIBCPP_PUSH_MACROS30#include <__undef_macros>3132_LIBCPP_BEGIN_NAMESPACE_STD3334#if _LIBCPP_STD_VER >= 203536namespace ranges {37template <range _Rp>38requires movable<_Rp> && (!__is_std_initializer_list<remove_cvref_t<_Rp>>)39class owning_view : public view_interface<owning_view<_Rp>> {40_Rp __r_ = _Rp();4142public:43_LIBCPP_HIDE_FROM_ABI owning_view()44requires default_initializable<_Rp>45= default;46_LIBCPP_HIDE_FROM_ABI constexpr owning_view(_Rp&& __r) : __r_(std::move(__r)) {}4748_LIBCPP_HIDE_FROM_ABI owning_view(owning_view&&) = default;49_LIBCPP_HIDE_FROM_ABI owning_view& operator=(owning_view&&) = default;5051_LIBCPP_HIDE_FROM_ABI constexpr _Rp& base() & noexcept { return __r_; }52_LIBCPP_HIDE_FROM_ABI constexpr const _Rp& base() const& noexcept { return __r_; }53_LIBCPP_HIDE_FROM_ABI constexpr _Rp&& base() && noexcept { return std::move(__r_); }54_LIBCPP_HIDE_FROM_ABI constexpr const _Rp&& base() const&& noexcept { return std::move(__r_); }5556_LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Rp> begin() { return ranges::begin(__r_); }57_LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Rp> end() { return ranges::end(__r_); }58_LIBCPP_HIDE_FROM_ABI constexpr auto begin() const59requires range<const _Rp>60{61return ranges::begin(__r_);62}63_LIBCPP_HIDE_FROM_ABI constexpr auto end() const64requires range<const _Rp>65{66return ranges::end(__r_);67}6869_LIBCPP_HIDE_FROM_ABI constexpr bool empty()70requires requires { ranges::empty(__r_); }71{72return ranges::empty(__r_);73}74_LIBCPP_HIDE_FROM_ABI constexpr bool empty() const75requires requires { ranges::empty(__r_); }76{77return ranges::empty(__r_);78}7980_LIBCPP_HIDE_FROM_ABI constexpr auto size()81requires sized_range<_Rp>82{83return ranges::size(__r_);84}85_LIBCPP_HIDE_FROM_ABI constexpr auto size() const86requires sized_range<const _Rp>87{88return ranges::size(__r_);89}9091_LIBCPP_HIDE_FROM_ABI constexpr auto data()92requires contiguous_range<_Rp>93{94return ranges::data(__r_);95}96_LIBCPP_HIDE_FROM_ABI constexpr auto data() const97requires contiguous_range<const _Rp>98{99return ranges::data(__r_);100}101};102_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(owning_view);103104template <class _Tp>105inline constexpr bool enable_borrowed_range<owning_view<_Tp>> = enable_borrowed_range<_Tp>;106107} // namespace ranges108109#endif // _LIBCPP_STD_VER >= 20110111_LIBCPP_END_NAMESPACE_STD112113_LIBCPP_POP_MACROS114115#endif // _LIBCPP___RANGES_OWNING_VIEW_H116117118