| 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-exception |
| 7 |
// |
| 8 |
//===----------------------------------------------------------------------===// |
| 9 |
|
| 10 |
#ifndef _LIBCPP___RANGES_EMPTY_H |
| 11 |
#define _LIBCPP___RANGES_EMPTY_H |
| 12 |
|
| 13 |
#include <__concepts/class_or_enum.h> |
| 14 |
#include <__config> |
| 15 |
#include <__iterator/concepts.h> |
| 16 |
#include <__ranges/access.h> |
| 17 |
#include <__ranges/size.h> |
| 18 |
|
| 19 |
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 20 |
# pragma GCC system_header |
| 21 |
#endif |
| 22 |
|
| 23 |
_LIBCPP_BEGIN_NAMESPACE_STD |
| 24 |
|
| 25 |
#if _LIBCPP_STD_VER >= 20 |
| 26 |
|
| 27 |
// [range.prim.empty] |
| 28 |
|
| 29 |
namespace ranges { |
| 30 |
namespace __empty { |
| 31 |
template <class _Tp> |
| 32 |
concept __member_empty = requires(_Tp&& __t) { bool(__t.empty()); }; |
| 33 |
|
| 34 |
template <class _Tp> |
| 35 |
concept __can_invoke_size = !__member_empty<_Tp> && requires(_Tp&& __t) { ranges::size(__t); }; |
| 36 |
|
| 37 |
template <class _Tp> |
| 38 |
concept __can_compare_begin_end = !__member_empty<_Tp> && !__can_invoke_size<_Tp> && requires(_Tp&& __t) { |
| 39 |
bool(ranges::begin(__t) == ranges::end(__t)); |
| 40 |
{ ranges::begin(__t) } -> forward_iterator; |
| 41 |
}; |
| 42 |
|
| 43 |
struct __fn { |
| 44 |
template <__member_empty _Tp> |
| 45 |
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const noexcept(noexcept(bool(__t.empty()))) { |
| 46 |
return bool(__t.empty()); |
| 47 |
} |
| 48 |
|
| 49 |
template <__can_invoke_size _Tp> |
| 50 |
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const noexcept(noexcept(ranges::size(__t))) { |
| 51 |
return ranges::size(__t) == 0; |
| 52 |
} |
| 53 |
|
| 54 |
template <__can_compare_begin_end _Tp> |
| 55 |
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const |
| 56 |
noexcept(noexcept(bool(ranges::begin(__t) == ranges::end(__t)))) { |
| 57 |
return ranges::begin(__t) == ranges::end(__t); |
| 58 |
} |
| 59 |
}; |
| 60 |
} // namespace __empty |
| 61 |
|
| 62 |
inline namespace __cpo { |
| 63 |
inline constexpr auto empty = __empty::__fn{}; |
| 64 |
} // namespace __cpo |
| 65 |
} // namespace ranges |
| 66 |
|
| 67 |
#endif // _LIBCPP_STD_VER >= 20 |
| 68 |
|
| 69 |
_LIBCPP_END_NAMESPACE_STD |
| 70 |
|
| 71 |
#endif // _LIBCPP___RANGES_EMPTY_H |