summaryrefslogtreecommitdiff
path: root/kernel/lib/libcxx/include/__utility/move.h
blob: 048eb069c60d8451102e8079f0094e7ee806b7a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the BastionOS freestanding C++ standard library.
//
//===----------------------------------------------------------------------===//

#ifndef _LIBBASTION_UTILITY_MOVE_H
#define _LIBBASTION_UTILITY_MOVE_H

#include <__config>
#include <__type_traits/other_transformations.h>

_LIBBASTION_BEGIN_NAMESPACE_STD

template<class _Tp>
_LIBBASTION_NODISCARD inline constexpr __remove_reference_t(_Tp)&& move(_Tp&& __t) noexcept {
    return static_cast<__remove_reference_t(_Tp)&&>(__t);
}

template<class _Tp>
_LIBBASTION_NODISCARD inline constexpr _Tp&& forward(__remove_reference_t(_Tp)& __t) noexcept {
    return static_cast<_Tp&&>(__t);
}

template<class _Tp>
_LIBBASTION_NODISCARD inline constexpr _Tp&& forward(__remove_reference_t(_Tp)&& __t) noexcept {
    static_assert(!__is_lvalue_reference(_Tp), "cannot forward an rvalue as an lvalue");
    return static_cast<_Tp&&>(__t);
}

template<class _Tp>
_LIBBASTION_NODISCARD inline constexpr
conditional_t<
    !__is_nothrow_constructible(_Tp, __add_rvalue_reference(_Tp)) &&
     __is_constructible(_Tp, __add_lvalue_reference(const _Tp)),
    const _Tp&,
    _Tp&&>
move_if_noexcept(_Tp& __x) noexcept {
    return std::move(__x);
}

_LIBBASTION_END_NAMESPACE_STD

#endif // _LIBBASTION_UTILITY_MOVE_H