Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:14:02

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___RANGES_EMPTY_H
0011 #define _LIBCPP___RANGES_EMPTY_H
0012 
0013 #include <__concepts/class_or_enum.h>
0014 #include <__config>
0015 #include <__iterator/concepts.h>
0016 #include <__ranges/access.h>
0017 #include <__ranges/size.h>
0018 
0019 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0020 #  pragma GCC system_header
0021 #endif
0022 
0023 _LIBCPP_BEGIN_NAMESPACE_STD
0024 
0025 #if _LIBCPP_STD_VER >= 20
0026 
0027 // [range.prim.empty]
0028 
0029 namespace ranges {
0030 namespace __empty {
0031 template <class _Tp>
0032 concept __member_empty = requires(_Tp&& __t) { bool(__t.empty()); };
0033 
0034 template <class _Tp>
0035 concept __can_invoke_size = !__member_empty<_Tp> && requires(_Tp&& __t) { ranges::size(__t); };
0036 
0037 template <class _Tp>
0038 concept __can_compare_begin_end = !__member_empty<_Tp> && !__can_invoke_size<_Tp> && requires(_Tp&& __t) {
0039   bool(ranges::begin(__t) == ranges::end(__t));
0040   { ranges::begin(__t) } -> forward_iterator;
0041 };
0042 
0043 struct __fn {
0044   template <__member_empty _Tp>
0045   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const noexcept(noexcept(bool(__t.empty()))) {
0046     return bool(__t.empty());
0047   }
0048 
0049   template <__can_invoke_size _Tp>
0050   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const noexcept(noexcept(ranges::size(__t))) {
0051     return ranges::size(__t) == 0;
0052   }
0053 
0054   template <__can_compare_begin_end _Tp>
0055   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const
0056       noexcept(noexcept(bool(ranges::begin(__t) == ranges::end(__t)))) {
0057     return ranges::begin(__t) == ranges::end(__t);
0058   }
0059 };
0060 } // namespace __empty
0061 
0062 inline namespace __cpo {
0063 inline constexpr auto empty = __empty::__fn{};
0064 } // namespace __cpo
0065 } // namespace ranges
0066 
0067 #endif // _LIBCPP_STD_VER >= 20
0068 
0069 _LIBCPP_END_NAMESPACE_STD
0070 
0071 #endif // _LIBCPP___RANGES_EMPTY_H