103 lines · c
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP___RANGES_DATA_H11#define _LIBCPP___RANGES_DATA_H12 13#include <__concepts/class_or_enum.h>14#include <__config>15#include <__iterator/concepts.h>16#include <__iterator/iterator_traits.h>17#include <__memory/pointer_traits.h>18#include <__ranges/access.h>19#include <__type_traits/decay.h>20#include <__type_traits/is_object.h>21#include <__type_traits/is_pointer.h>22#include <__type_traits/is_reference.h>23#include <__type_traits/remove_pointer.h>24#include <__type_traits/remove_reference.h>25#include <__utility/auto_cast.h>26 27#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)28# pragma GCC system_header29#endif30 31_LIBCPP_BEGIN_NAMESPACE_STD32 33#if _LIBCPP_STD_VER >= 2034 35// [range.prim.data]36 37namespace ranges {38namespace __data {39template <class _Tp>40concept __ptr_to_object = is_pointer_v<_Tp> && is_object_v<remove_pointer_t<_Tp>>;41 42template <class _Tp>43concept __member_data = __can_borrow<_Tp> && requires(_Tp&& __t) {44 { _LIBCPP_AUTO_CAST(__t.data()) } -> __ptr_to_object;45};46 47template <class _Tp>48concept __ranges_begin_invocable = !__member_data<_Tp> && __can_borrow<_Tp> && requires(_Tp&& __t) {49 { ranges::begin(__t) } -> contiguous_iterator;50};51 52struct __fn {53 template <__member_data _Tp>54 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const noexcept(noexcept(__t.data())) {55 return __t.data();56 }57 58 template <__ranges_begin_invocable _Tp>59 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const60 noexcept(noexcept(std::to_address(ranges::begin(__t)))) {61 return std::to_address(ranges::begin(__t));62 }63};64} // namespace __data65 66inline namespace __cpo {67inline constexpr auto data = __data::__fn{};68} // namespace __cpo69} // namespace ranges70 71// [range.prim.cdata]72 73namespace ranges {74namespace __cdata {75struct __fn {76 template <class _Tp>77 requires is_lvalue_reference_v<_Tp&&>78 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const79 noexcept(noexcept(ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t))))80 -> decltype(ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t))) {81 return ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t));82 }83 84 template <class _Tp>85 requires is_rvalue_reference_v<_Tp&&>86 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const noexcept(87 noexcept(ranges::data(static_cast<const _Tp&&>(__t)))) -> decltype(ranges::data(static_cast<const _Tp&&>(__t))) {88 return ranges::data(static_cast<const _Tp&&>(__t));89 }90};91} // namespace __cdata92 93inline namespace __cpo {94inline constexpr auto cdata = __cdata::__fn{};95} // namespace __cpo96} // namespace ranges97 98#endif // _LIBCPP_STD_VER >= 2099 100_LIBCPP_END_NAMESPACE_STD101 102#endif // _LIBCPP___RANGES_DATA_H103