libbmb
Modern implementation of STL
Loading...
Searching...
No Matches
move.h
Go to the documentation of this file.
1#pragma once
8#include "utils/type_traits.h"
9
10namespace bmb {
11
17template <typename T>
18[[nodiscard("Move should be used to initialize other object")]]
19constexpr remove_ref_t<T>&& move(T&& value) noexcept {
20 // Universal reference as a parameter allows to move already rvalue
21 // expressions. Therefore returning type should remove reference from the
22 // deduced type(see reference collapsing rules)
23 return static_cast<remove_ref_t<T>&&>(value);
24}
25
31template <typename T>
32[[nodiscard("Forward should be used to initialize other object")]]
33constexpr T&& forward(remove_ref_t<T>& value) noexcept {
34 return static_cast<T&&>(value);
35}
36
42template <typename T>
43 requires(!is_lvalue_ref_v<T>)
44[[nodiscard("Forward should be used to initialize other object")]]
45constexpr T&& forward(remove_ref_t<T>&& value) noexcept {
46 return static_cast<T&&>(value);
47}
48
59template <typename T>
60void swap(T& x, T& y) {
61 T tmp = move(x);
62
63 x = move(y);
64 y = move(tmp);
65}
66
67} // namespace bmb
Definition algo_base.h:14
constexpr remove_ref_t< T > && move(T &&value) noexcept
Convert a value to xvalue.
Definition move.h:19
void swap(LinkedList< T, TrackSize, TrackLast, Allocator > &a, LinkedList< T, TrackSize, TrackLast, Allocator > &b)
See LinkedList::swap
Definition linked_list.h:1026
remove_ref< T >::type remove_ref_t
remove_ref_t
Definition type_traits.h:182
constexpr T && forward(remove_ref_t< T > &value) noexcept
Forward a lvalue.
Definition move.h:33