Path: blob/main/contrib/llvm-project/libcxx/include/__ranges/data.h
35236 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_DATA_H10#define _LIBCPP___RANGES_DATA_H1112#include <__concepts/class_or_enum.h>13#include <__config>14#include <__iterator/concepts.h>15#include <__iterator/iterator_traits.h>16#include <__memory/pointer_traits.h>17#include <__ranges/access.h>18#include <__type_traits/decay.h>19#include <__type_traits/is_object.h>20#include <__type_traits/is_pointer.h>21#include <__type_traits/is_reference.h>22#include <__type_traits/remove_pointer.h>23#include <__type_traits/remove_reference.h>24#include <__utility/auto_cast.h>2526#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)27# pragma GCC system_header28#endif2930_LIBCPP_BEGIN_NAMESPACE_STD3132#if _LIBCPP_STD_VER >= 203334// [range.prim.data]3536namespace ranges {37namespace __data {38template <class _Tp>39concept __ptr_to_object = is_pointer_v<_Tp> && is_object_v<remove_pointer_t<_Tp>>;4041template <class _Tp>42concept __member_data = __can_borrow<_Tp> && requires(_Tp&& __t) {43{ _LIBCPP_AUTO_CAST(__t.data()) } -> __ptr_to_object;44};4546template <class _Tp>47concept __ranges_begin_invocable = !__member_data<_Tp> && __can_borrow<_Tp> && requires(_Tp&& __t) {48{ ranges::begin(__t) } -> contiguous_iterator;49};5051struct __fn {52template <__member_data _Tp>53_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const noexcept(noexcept(__t.data())) {54return __t.data();55}5657template <__ranges_begin_invocable _Tp>58_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const59noexcept(noexcept(std::to_address(ranges::begin(__t)))) {60return std::to_address(ranges::begin(__t));61}62};63} // namespace __data6465inline namespace __cpo {66inline constexpr auto data = __data::__fn{};67} // namespace __cpo68} // namespace ranges6970// [range.prim.cdata]7172namespace ranges {73namespace __cdata {74struct __fn {75template <class _Tp>76requires is_lvalue_reference_v<_Tp&&>77[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const78noexcept(noexcept(ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t))))79-> decltype(ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t))) {80return ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t));81}8283template <class _Tp>84requires is_rvalue_reference_v<_Tp&&>85[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const noexcept(86noexcept(ranges::data(static_cast<const _Tp&&>(__t)))) -> decltype(ranges::data(static_cast<const _Tp&&>(__t))) {87return ranges::data(static_cast<const _Tp&&>(__t));88}89};90} // namespace __cdata9192inline namespace __cpo {93inline constexpr auto cdata = __cdata::__fn{};94} // namespace __cpo95} // namespace ranges9697#endif // _LIBCPP_STD_VER >= 209899_LIBCPP_END_NAMESPACE_STD100101#endif // _LIBCPP___RANGES_DATA_H102103104