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