[libc] Fix improper initialization of `StorageType` (#75610)
[llvm-project.git] / libcxx / include / __ranges / empty.h
blob64996f4a6f7b0c116ec0a386a11ae33d4ad3c63e
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 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___RANGES_EMPTY_H
11 #define _LIBCPP___RANGES_EMPTY_H
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>
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 # pragma GCC system_header
21 #endif
23 _LIBCPP_BEGIN_NAMESPACE_STD
25 #if _LIBCPP_STD_VER >= 20
27 // [range.prim.empty]
29 namespace ranges {
30 namespace __empty {
31 template <class _Tp>
32 concept __member_empty =
33 __workaround_52970<_Tp> &&
34 requires(_Tp&& __t) {
35 bool(__t.empty());
38 template<class _Tp>
39 concept __can_invoke_size =
40 !__member_empty<_Tp> &&
41 requires(_Tp&& __t) { ranges::size(__t); };
43 template <class _Tp>
44 concept __can_compare_begin_end =
45 !__member_empty<_Tp> &&
46 !__can_invoke_size<_Tp> &&
47 requires(_Tp&& __t) {
48 bool(ranges::begin(__t) == ranges::end(__t));
49 { ranges::begin(__t) } -> forward_iterator;
52 struct __fn {
53 template <__member_empty _Tp>
54 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const
55 noexcept(noexcept(bool(__t.empty()))) {
56 return bool(__t.empty());
59 template <__can_invoke_size _Tp>
60 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const
61 noexcept(noexcept(ranges::size(__t))) {
62 return ranges::size(__t) == 0;
65 template<__can_compare_begin_end _Tp>
66 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const
67 noexcept(noexcept(bool(ranges::begin(__t) == ranges::end(__t)))) {
68 return ranges::begin(__t) == ranges::end(__t);
71 } // namespace __empty
73 inline namespace __cpo {
74 inline constexpr auto empty = __empty::__fn{};
75 } // namespace __cpo
76 } // namespace ranges
78 #endif // _LIBCPP_STD_VER >= 20
80 _LIBCPP_END_NAMESPACE_STD
82 #endif // _LIBCPP___RANGES_EMPTY_H