2021-04-23 12:34:22 -07:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2022-11-25 10:25:10 -05:00
|
|
|
|
2021-04-23 12:34:22 -07:00
|
|
|
#ifndef _LIBCPP___RANGES_EMPTY_H
|
|
|
|
#define _LIBCPP___RANGES_EMPTY_H
|
|
|
|
|
2021-12-23 16:53:48 -05:00
|
|
|
#include <__concepts/class_or_enum.h>
|
2021-04-23 12:34:22 -07:00
|
|
|
#include <__config>
|
|
|
|
#include <__iterator/concepts.h>
|
2021-06-12 06:13:44 +00:00
|
|
|
#include <__ranges/access.h>
|
2021-04-23 12:34:22 -07:00
|
|
|
#include <__ranges/size.h>
|
|
|
|
|
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-01 20:16:40 -05:00
|
|
|
# pragma GCC system_header
|
2021-04-23 12:34:22 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2023-02-14 00:56:09 +01:00
|
|
|
#if _LIBCPP_STD_VER >= 20
|
2021-04-23 12:34:22 -07:00
|
|
|
|
|
|
|
// [range.prim.empty]
|
2021-12-23 14:51:24 -05:00
|
|
|
|
|
|
|
namespace ranges {
|
2021-04-23 12:34:22 -07:00
|
|
|
namespace __empty {
|
|
|
|
template <class _Tp>
|
2024-03-20 01:49:31 -07:00
|
|
|
concept __member_empty = requires(_Tp&& __t) { bool(__t.empty()); };
|
2023-12-18 14:01:33 -05:00
|
|
|
|
2021-04-23 12:34:22 -07:00
|
|
|
template <class _Tp>
|
2021-12-22 18:06:48 -05:00
|
|
|
concept __can_invoke_size = !__member_empty<_Tp> && requires(_Tp&& __t) { ranges::size(__t); };
|
2023-12-18 14:01:33 -05:00
|
|
|
|
2021-04-23 12:34:22 -07:00
|
|
|
template <class _Tp>
|
|
|
|
concept __can_compare_begin_end = !__member_empty<_Tp> && !__can_invoke_size<_Tp> && requires(_Tp&& __t) {
|
|
|
|
bool(ranges::begin(__t) == ranges::end(__t));
|
|
|
|
{ ranges::begin(__t) } -> forward_iterator;
|
|
|
|
};
|
2023-12-18 14:01:33 -05:00
|
|
|
|
2021-04-23 12:34:22 -07:00
|
|
|
struct __fn {
|
|
|
|
template <__member_empty _Tp>
|
2021-07-19 12:34:56 -04:00
|
|
|
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const noexcept(noexcept(bool(__t.empty()))) {
|
2021-12-22 18:06:48 -05:00
|
|
|
return bool(__t.empty());
|
2021-04-23 12:34:22 -07:00
|
|
|
}
|
2023-12-18 14:01:33 -05:00
|
|
|
|
2021-04-23 12:34:22 -07:00
|
|
|
template <__can_invoke_size _Tp>
|
2021-07-19 12:34:56 -04:00
|
|
|
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const noexcept(noexcept(ranges::size(__t))) {
|
2021-12-22 18:06:48 -05:00
|
|
|
return ranges::size(__t) == 0;
|
2021-04-23 12:34:22 -07:00
|
|
|
}
|
2023-12-18 14:01:33 -05:00
|
|
|
|
2021-04-23 12:34:22 -07:00
|
|
|
template <__can_compare_begin_end _Tp>
|
2021-07-19 12:34:56 -04:00
|
|
|
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const
|
2021-04-23 12:34:22 -07:00
|
|
|
noexcept(noexcept(bool(ranges::begin(__t) == ranges::end(__t)))) {
|
|
|
|
return ranges::begin(__t) == ranges::end(__t);
|
|
|
|
}
|
|
|
|
};
|
2022-02-01 18:11:49 +01:00
|
|
|
} // namespace __empty
|
2021-04-23 12:34:22 -07:00
|
|
|
|
|
|
|
inline namespace __cpo {
|
|
|
|
inline constexpr auto empty = __empty::__fn{};
|
|
|
|
} // namespace __cpo
|
|
|
|
} // namespace ranges
|
|
|
|
|
2023-02-14 00:56:09 +01:00
|
|
|
#endif // _LIBCPP_STD_VER >= 20
|
2021-04-23 12:34:22 -07:00
|
|
|
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
|
|
|
#endif // _LIBCPP___RANGES_EMPTY_H
|