Sunshine
latest
Self-hosted game stream host for Moonlight.
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
:
21
typedef
T move_type;
22
23
private
:
24
move_type _to_move;
25
26
public
:
27
explicit
MoveByCopy
(move_type &&to_move):
28
_to_move(std::move(to_move)) {
29
}
30
31
MoveByCopy
(
MoveByCopy
&&other) =
default
;
32
33
MoveByCopy
(
const
MoveByCopy
&other) {
34
*
this
= other;
35
}
36
37
MoveByCopy
&operator=(
MoveByCopy
&&other) =
default
;
38
39
MoveByCopy
&operator=(
const
MoveByCopy
&other) {
40
this->_to_move = std::move(
const_cast<
MoveByCopy
&
>
(other)._to_move);
41
42
return
*
this
;
43
}
44
45
operator
move_type() {
46
return
std::move(_to_move);
47
}
48
};
49
50
template
<
class
T>
51
MoveByCopy<T>
cmove(T &movable) {
52
return
MoveByCopy<T>
(std::move(movable));
53
}
54
55
// Do NOT use this unless you are absolutely certain the object to be moved is no longer used by the caller
56
template
<
class
T>
57
MoveByCopy<T> const_cmove(
const
T &movable) {
58
return
MoveByCopy<T>(std::move(
const_cast<
T &
>
(movable)));
59
}
60
}
// namespace move_by_copy_util
move_by_copy_util::MoveByCopy
Definition
move_by_copy.h:19
move_by_copy_util
Contains utilities for moving objects by copying them.
Definition
move_by_copy.h:13
src
move_by_copy.h
Generated by
1.10.0