Sunshine
v2025.118.151840
Self-hosted game stream host for Moonlight.
move_by_copy.h
Go to the documentation of this file.
1
5
#pragma once
6
7
#include <utility>
8
12
namespace
move_by_copy_util
{
17
template
<
class
T>
18
class
MoveByCopy
{
19
public
:
20
typedef
T move_type;
21
22
private
:
23
move_type _to_move;
24
25
public
:
26
explicit
MoveByCopy
(move_type &&to_move):
27
_to_move(std::move(to_move)) {}
28
29
MoveByCopy
(
MoveByCopy
&&other) =
default
;
30
31
MoveByCopy
(
const
MoveByCopy
&other) {
32
*
this
= other;
33
}
34
35
MoveByCopy
&
36
operator=(
MoveByCopy
&&other) =
default
;
37
38
MoveByCopy
&
39
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>
52
cmove(T &movable) {
53
return
MoveByCopy<T>
(std::move(movable));
54
}
55
56
// Do NOT use this unless you are absolutely certain the object to be moved is no longer used by the caller
57
template
<
class
T>
58
MoveByCopy<T>
59
const_cmove(
const
T &movable) {
60
return
MoveByCopy<T>(std::move(
const_cast<
T &
>
(movable)));
61
}
62
}
// namespace move_by_copy_util
move_by_copy_util::MoveByCopy
Definition
move_by_copy.h:18
move_by_copy_util
Contains utilities for moving objects by copying them.
Definition
move_by_copy.h:12
src
move_by_copy.h
Generated by
1.10.0