Path: blob/main/contrib/llvm-project/libcxx/include/__ranges/empty.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_EMPTY_H10#define _LIBCPP___RANGES_EMPTY_H1112#include <__concepts/class_or_enum.h>13#include <__config>14#include <__iterator/concepts.h>15#include <__ranges/access.h>16#include <__ranges/size.h>1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)19# pragma GCC system_header20#endif2122_LIBCPP_BEGIN_NAMESPACE_STD2324#if _LIBCPP_STD_VER >= 202526// [range.prim.empty]2728namespace ranges {29namespace __empty {30template <class _Tp>31concept __member_empty = requires(_Tp&& __t) { bool(__t.empty()); };3233template <class _Tp>34concept __can_invoke_size = !__member_empty<_Tp> && requires(_Tp&& __t) { ranges::size(__t); };3536template <class _Tp>37concept __can_compare_begin_end = !__member_empty<_Tp> && !__can_invoke_size<_Tp> && requires(_Tp&& __t) {38bool(ranges::begin(__t) == ranges::end(__t));39{ ranges::begin(__t) } -> forward_iterator;40};4142struct __fn {43template <__member_empty _Tp>44[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const noexcept(noexcept(bool(__t.empty()))) {45return bool(__t.empty());46}4748template <__can_invoke_size _Tp>49[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const noexcept(noexcept(ranges::size(__t))) {50return ranges::size(__t) == 0;51}5253template <__can_compare_begin_end _Tp>54[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const55noexcept(noexcept(bool(ranges::begin(__t) == ranges::end(__t)))) {56return ranges::begin(__t) == ranges::end(__t);57}58};59} // namespace __empty6061inline namespace __cpo {62inline constexpr auto empty = __empty::__fn{};63} // namespace __cpo64} // namespace ranges6566#endif // _LIBCPP_STD_VER >= 206768_LIBCPP_END_NAMESPACE_STD6970#endif // _LIBCPP___RANGES_EMPTY_H717273