2021-04-23 19:34:22 +00: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 15:25:10 +00:00
|
|
|
|
2021-04-23 19:34:22 +00:00
|
|
|
#ifndef _LIBCPP___RANGES_EMPTY_H
|
|
|
|
#define _LIBCPP___RANGES_EMPTY_H
|
|
|
|
|
2021-12-23 21:53:48 +00:00
|
|
|
#include <__concepts/class_or_enum.h>
|
2021-04-23 19:34:22 +00:00
|
|
|
#include <__config>
|
|
|
|
#include <__iterator/concepts.h>
|
2021-06-12 06:13:44 +00:00
|
|
|
#include <__ranges/access.h>
|
2021-04-23 19:34:22 +00:00
|
|
|
#include <__ranges/size.h>
|
|
|
|
|
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-02 01:16:40 +00:00
|
|
|
# pragma GCC system_header
|
2021-04-23 19:34:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2023-02-13 23:56:09 +00:00
|
|
|
#if _LIBCPP_STD_VER >= 20
|
2021-04-23 19:34:22 +00:00
|
|
|
|
|
|
|
// [range.prim.empty]
|
2021-12-23 19:51:24 +00:00
|
|
|
|
|
|
|
namespace ranges {
|
2021-04-23 19:34:22 +00:00
|
|
|
namespace __empty {
|
|
|
|
template <class _Tp>
|
2021-12-23 21:53:48 +00:00
|
|
|
concept __member_empty = __workaround_52970<_Tp> && requires(_Tp&& __t) { bool(__t.empty()); };
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2021-04-23 19:34:22 +00:00
|
|
|
template <class _Tp>
|
2021-12-22 23:06:48 +00:00
|
|
|
concept __can_invoke_size = !__member_empty<_Tp> && requires(_Tp&& __t) { ranges::size(__t); };
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2021-04-23 19:34:22 +00: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 19:01:33 +00:00
|
|
|
|
2021-04-23 19:34:22 +00:00
|
|
|
struct __fn {
|
|
|
|
template <__member_empty _Tp>
|
2021-07-19 16:34:56 +00:00
|
|
|
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const noexcept(noexcept(bool(__t.empty()))) {
|
2021-12-22 23:06:48 +00:00
|
|
|
return bool(__t.empty());
|
2021-04-23 19:34:22 +00:00
|
|
|
}
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2021-04-23 19:34:22 +00:00
|
|
|
template <__can_invoke_size _Tp>
|
2021-07-19 16:34:56 +00:00
|
|
|
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const noexcept(noexcept(ranges::size(__t))) {
|
2021-12-22 23:06:48 +00:00
|
|
|
return ranges::size(__t) == 0;
|
2021-04-23 19:34:22 +00:00
|
|
|
}
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2021-04-23 19:34:22 +00:00
|
|
|
template <__can_compare_begin_end _Tp>
|
2021-07-19 16:34:56 +00:00
|
|
|
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const
|
2021-04-23 19:34:22 +00:00
|
|
|
noexcept(noexcept(bool(ranges::begin(__t) == ranges::end(__t)))) {
|
|
|
|
return ranges::begin(__t) == ranges::end(__t);
|
|
|
|
}
|
|
|
|
};
|
2022-02-01 17:11:49 +00:00
|
|
|
} // namespace __empty
|
2021-04-23 19:34:22 +00:00
|
|
|
|
|
|
|
inline namespace __cpo {
|
|
|
|
inline constexpr auto empty = __empty::__fn{};
|
|
|
|
} // namespace __cpo
|
|
|
|
} // namespace ranges
|
|
|
|
|
2023-02-13 23:56:09 +00:00
|
|
|
#endif // _LIBCPP_STD_VER >= 20
|
2021-04-23 19:34:22 +00:00
|
|
|
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
|
|
|
#endif // _LIBCPP___RANGES_EMPTY_H
|