move_sentinel.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #ifndef _LIBCPP___ITERATOR_MOVE_SENTINEL_H
  9. #define _LIBCPP___ITERATOR_MOVE_SENTINEL_H
  10. #include <__concepts/assignable.h>
  11. #include <__concepts/convertible_to.h>
  12. #include <__concepts/semiregular.h>
  13. #include <__config>
  14. #include <__utility/move.h>
  15. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  16. # pragma GCC system_header
  17. #endif
  18. _LIBCPP_PUSH_MACROS
  19. #include <__undef_macros>
  20. _LIBCPP_BEGIN_NAMESPACE_STD
  21. #if _LIBCPP_STD_VER >= 20
  22. template <semiregular _Sent>
  23. class _LIBCPP_TEMPLATE_VIS move_sentinel
  24. {
  25. public:
  26. _LIBCPP_HIDE_FROM_ABI
  27. move_sentinel() = default;
  28. _LIBCPP_HIDE_FROM_ABI constexpr
  29. explicit move_sentinel(_Sent __s) : __last_(std::move(__s)) {}
  30. template <class _S2>
  31. requires convertible_to<const _S2&, _Sent>
  32. _LIBCPP_HIDE_FROM_ABI constexpr
  33. move_sentinel(const move_sentinel<_S2>& __s) : __last_(__s.base()) {}
  34. template <class _S2>
  35. requires assignable_from<_Sent&, const _S2&>
  36. _LIBCPP_HIDE_FROM_ABI constexpr
  37. move_sentinel& operator=(const move_sentinel<_S2>& __s)
  38. { __last_ = __s.base(); return *this; }
  39. _LIBCPP_HIDE_FROM_ABI constexpr _Sent base() const { return __last_; }
  40. private:
  41. _Sent __last_ = _Sent();
  42. };
  43. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(move_sentinel);
  44. #endif // _LIBCPP_STD_VER >= 20
  45. _LIBCPP_END_NAMESPACE_STD
  46. _LIBCPP_POP_MACROS
  47. #endif // _LIBCPP___ITERATOR_MOVE_SENTINEL_H