Sunshine
latest
Self-hosted game stream host for Moonlight.
Toggle main menu visibility
move_by_copy.h
Go to the documentation of this file.
1
5
#pragma once
6
7
// standard includes
8
#include <utility>
9
13
namespace
move_by_copy_util
{
18
template
<
class
T>
19
class
MoveByCopy
{
20
public
:
24
typedef
T
move_type
;
25
26
private
:
27
move_type
_to_move;
28
29
public
:
35
explicit
MoveByCopy
(
move_type
&&to_move):
36
_to_move(std::move(to_move)) {
37
}
38
44
MoveByCopy
(
MoveByCopy
&&other) =
default
;
45
51
MoveByCopy
(
const
MoveByCopy
&other) {
52
*
this
= other;
53
}
54
61
MoveByCopy
&
operator=
(
MoveByCopy
&&other) =
default
;
62
69
MoveByCopy
&
operator=
(
const
MoveByCopy
&other) {
70
this->_to_move = std::move(
const_cast<
MoveByCopy
&
>
(other)._to_move);
71
72
return
*
this
;
73
}
74
78
operator
move_type
() {
79
return
std::move(_to_move);
80
}
81
};
82
89
template
<
class
T>
90
MoveByCopy<T>
cmove
(T &movable) {
91
return
MoveByCopy<T>
(std::move(movable));
92
}
93
94
// Do NOT use this unless you are absolutely certain the object to be moved is no longer used by the caller
101
template
<
class
T>
102
MoveByCopy<T>
const_cmove
(
const
T &movable) {
103
return
MoveByCopy<T>
(std::move(
const_cast<
T &
>
(movable)));
104
}
105
}
// namespace move_by_copy_util
move_by_copy_util::MoveByCopy
Definition
move_by_copy.h:19
move_by_copy_util::MoveByCopy::MoveByCopy
MoveByCopy(const MoveByCopy &other)
Copy by moving the stored object out of another wrapper.
Definition
move_by_copy.h:51
move_by_copy_util::MoveByCopy::operator=
MoveByCopy & operator=(MoveByCopy &&other)=default
Move-assign the wrapped object from another wrapper.
move_by_copy_util::MoveByCopy::operator=
MoveByCopy & operator=(const MoveByCopy &other)
Copy-assign by moving the wrapped object out of the source wrapper.
Definition
move_by_copy.h:69
move_by_copy_util::MoveByCopy::MoveByCopy
MoveByCopy(move_type &&to_move)
Store a move-only value for transfer through copy-only call sites.
Definition
move_by_copy.h:35
move_by_copy_util::MoveByCopy::move_type
T move_type
Wrapped type moved through copy-shaped APIs.
Definition
move_by_copy.h:24
move_by_copy_util::MoveByCopy::MoveByCopy
MoveByCopy(MoveByCopy &&other)=default
Move the stored object from another wrapper.
move_by_copy_util
Contains utilities for moving objects by copying them.
Definition
move_by_copy.h:13
move_by_copy_util::const_cmove
MoveByCopy< T > const_cmove(const T &movable)
Copy-shape wrapper for moving from a const reference.
Definition
move_by_copy.h:102
move_by_copy_util::cmove
MoveByCopy< T > cmove(T &movable)
Copy a move-only value by moving from the source reference.
Definition
move_by_copy.h:90
src
move_by_copy.h
Generated by
1.18.0