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
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
36 operator=(MoveByCopy &&other) = default;
37
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>
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
Definition move_by_copy.h:18
Contains utilities for moving objects by copying them.
Definition move_by_copy.h:12