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___UTILITY_MOVE_H
11#define _LIBCPP___UTILITY_MOVE_H
12
13#include <__config>
14#include <__type_traits/conditional.h>
15#include <__type_traits/is_constructible.h>
16#include <__type_traits/is_nothrow_constructible.h>
17#include <__type_traits/remove_reference.h>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
26_LIBCPP_BEGIN_NAMESPACE_STD
27
28template <class _Tp>
29_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __libcpp_remove_reference_t<_Tp>&&
30move(_LIBCPP_LIFETIMEBOUND _Tp&& __t) _NOEXCEPT {
31 typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tp> _Up;
32 return static_cast<_Up&&>(__t);
33}
34
35template <class _Tp>
36using __move_if_noexcept_result_t =
37 __conditional_t<!is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, const _Tp&, _Tp&&>;
38
39template <class _Tp>
40_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __move_if_noexcept_result_t<_Tp>
41move_if_noexcept(_LIBCPP_LIFETIMEBOUND _Tp& __x) _NOEXCEPT {
42 return std::move(__x);
43}
44
45_LIBCPP_END_NAMESPACE_STD
46
47_LIBCPP_POP_MACROS
48
49#endif // _LIBCPP___UTILITY_MOVE_H
50