move_sentinel.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_BEGIN_NAMESPACE_STD
  19. #if _LIBCPP_STD_VER > 17
  20. template <semiregular _Sent>
  21. class _LIBCPP_TEMPLATE_VIS move_sentinel
  22. {
  23. public:
  24. _LIBCPP_HIDE_FROM_ABI
  25. move_sentinel() = default;
  26. _LIBCPP_HIDE_FROM_ABI constexpr
  27. explicit move_sentinel(_Sent __s) : __last_(std::move(__s)) {}
  28. template <class _S2>
  29. requires convertible_to<const _S2&, _Sent>
  30. _LIBCPP_HIDE_FROM_ABI constexpr
  31. move_sentinel(const move_sentinel<_S2>& __s) : __last_(__s.base()) {}
  32. template <class _S2>
  33. requires assignable_from<_Sent&, const _S2&>
  34. _LIBCPP_HIDE_FROM_ABI constexpr
  35. move_sentinel& operator=(const move_sentinel<_S2>& __s)
  36. { __last_ = __s.base(); return *this; }
  37. constexpr _Sent base() const { return __last_; }
  38. private:
  39. _Sent __last_ = _Sent();
  40. };
  41. _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(move_sentinel);
  42. #endif // _LIBCPP_STD_VER > 17
  43. _LIBCPP_END_NAMESPACE_STD
  44. #endif // _LIBCPP___ITERATOR_MOVE_SENTINEL_H