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
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
Definition move_by_copy.h:19
Contains utilities for moving objects by copying them.
Definition move_by_copy.h:13