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