xref: /freebsd/contrib/llvm-project/libcxx/include/__memory/concepts.h (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
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___MEMORY_CONCEPTS_H
11 #define _LIBCPP___MEMORY_CONCEPTS_H
12 
13 #include <__concepts/same_as.h>
14 #include <__config>
15 #include <__iterator/concepts.h>
16 #include <__iterator/iterator_traits.h>
17 #include <__iterator/readable_traits.h>
18 #include <__ranges/access.h>
19 #include <__ranges/concepts.h>
20 #include <__type_traits/is_reference.h>
21 #include <__type_traits/remove_cvref.h>
22 #include <__type_traits/remove_reference.h> // TODO(modules): This should not be required
23 
24 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25 #  pragma GCC system_header
26 #endif
27 
28 _LIBCPP_BEGIN_NAMESPACE_STD
29 
30 #if _LIBCPP_STD_VER >= 20
31 
32 namespace ranges {
33 
34 // [special.mem.concepts]
35 
36 // This concept ensures that uninitialized algorithms can construct an object
37 // at the address pointed-to by the iterator, which requires an lvalue.
38 template <class _Ip>
39 concept __nothrow_input_iterator =
40     input_iterator<_Ip> &&
41     is_lvalue_reference_v<iter_reference_t<_Ip>> &&
42     same_as<remove_cvref_t<iter_reference_t<_Ip>>, iter_value_t<_Ip>>;
43 
44 template <class _Sp, class _Ip>
45 concept __nothrow_sentinel_for = sentinel_for<_Sp, _Ip>;
46 
47 template <class _Rp>
48 concept __nothrow_input_range =
49     range<_Rp> &&
50     __nothrow_input_iterator<iterator_t<_Rp>> &&
51     __nothrow_sentinel_for<sentinel_t<_Rp>, iterator_t<_Rp>>;
52 
53 template <class _Ip>
54 concept __nothrow_forward_iterator =
55     __nothrow_input_iterator<_Ip> &&
56     forward_iterator<_Ip> &&
57     __nothrow_sentinel_for<_Ip, _Ip>;
58 
59 template <class _Rp>
60 concept __nothrow_forward_range =
61     __nothrow_input_range<_Rp> &&
62     __nothrow_forward_iterator<iterator_t<_Rp>>;
63 
64 } // namespace ranges
65 
66 #endif // _LIBCPP_STD_VER >= 20
67 
68 _LIBCPP_END_NAMESPACE_STD
69 
70 #endif // _LIBCPP___MEMORY_CONCEPTS_H
71