move.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. #ifndef _LIBCPP___UTILITY_MOVE_H
  10. #define _LIBCPP___UTILITY_MOVE_H
  11. #include <__config>
  12. #include <__type_traits/conditional.h>
  13. #include <__type_traits/is_copy_constructible.h>
  14. #include <__type_traits/is_nothrow_move_constructible.h>
  15. #include <__type_traits/remove_reference.h>
  16. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  17. # pragma GCC system_header
  18. #endif
  19. _LIBCPP_BEGIN_NAMESPACE_STD
  20. template <class _Tp>
  21. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __libcpp_remove_reference_t<_Tp>&&
  22. move(_LIBCPP_LIFETIMEBOUND _Tp&& __t) _NOEXCEPT {
  23. typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tp> _Up;
  24. return static_cast<_Up&&>(__t);
  25. }
  26. template <class _Tp>
  27. using __move_if_noexcept_result_t =
  28. __conditional_t<!is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, const _Tp&, _Tp&&>;
  29. template <class _Tp>
  30. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __move_if_noexcept_result_t<_Tp>
  31. move_if_noexcept(_LIBCPP_LIFETIMEBOUND _Tp& __x) _NOEXCEPT {
  32. return std::move(__x);
  33. }
  34. _LIBCPP_END_NAMESPACE_STD
  35. #endif // _LIBCPP___UTILITY_MOVE_H