1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef _LIBCPP___ITERATOR_MOVE_SENTINEL_H
10 #define _LIBCPP___ITERATOR_MOVE_SENTINEL_H
11 
12 #include <__concepts/assignable.h>
13 #include <__concepts/convertible_to.h>
14 #include <__concepts/semiregular.h>
15 #include <__config>
16 #include <__utility/move.h>
17 
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 #  pragma GCC system_header
20 #endif
21 
22 _LIBCPP_PUSH_MACROS
23 #include <__undef_macros>
24 
25 _LIBCPP_BEGIN_NAMESPACE_STD
26 
27 #if _LIBCPP_STD_VER >= 20
28 
29 template <semiregular _Sent>
30 class _LIBCPP_TEMPLATE_VIS move_sentinel
31 {
32 public:
33   _LIBCPP_HIDE_FROM_ABI
34   move_sentinel() = default;
35 
36   _LIBCPP_HIDE_FROM_ABI constexpr
37   explicit move_sentinel(_Sent __s) : __last_(std::move(__s)) {}
38 
39   template <class _S2>
40     requires convertible_to<const _S2&, _Sent>
41   _LIBCPP_HIDE_FROM_ABI constexpr
42   move_sentinel(const move_sentinel<_S2>& __s) : __last_(__s.base()) {}
43 
44   template <class _S2>
45     requires assignable_from<_Sent&, const _S2&>
46   _LIBCPP_HIDE_FROM_ABI constexpr
47   move_sentinel& operator=(const move_sentinel<_S2>& __s)
48     { __last_ = __s.base(); return *this; }
49 
50   _LIBCPP_HIDE_FROM_ABI constexpr _Sent base() const { return __last_; }
51 
52 private:
53     _Sent __last_ = _Sent();
54 };
55 
56 _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(move_sentinel);
57 
58 #endif // _LIBCPP_STD_VER >= 20
59 
60 _LIBCPP_END_NAMESPACE_STD
61 
62 _LIBCPP_POP_MACROS
63 
64 #endif // _LIBCPP___ITERATOR_MOVE_SENTINEL_H
65