Sunshine0.0.5917
Sunshine 0.0.5917
Self-hosted game stream host for Moonlight.
Loading...
Searching...
No Matches
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:
24 using move_type = T;
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
70 this->_to_move = std::move(const_cast<MoveByCopy &>(other)._to_move);
71
72 return *this;
73 }
74
80 explicit operator move_type() {
81 return std::move(_to_move);
82 }
83 };
84
91 template<class T>
92 MoveByCopy<T> cmove(T &movable) {
93 return MoveByCopy<T>(std::move(movable));
94 }
95
96 // Do NOT use this unless you are absolutely certain the object to be moved is no longer used by the caller
103 template<class T>
104 MoveByCopy<T> const_cmove(const T &movable) {
105 return MoveByCopy<T>(std::move(const_cast<T &>(movable)));
106 }
107} // namespace move_by_copy_util
Definition move_by_copy.h:19
MoveByCopy(const MoveByCopy &other)
Copy by moving the stored object out of another wrapper.
Definition move_by_copy.h:51
MoveByCopy & operator=(MoveByCopy &&other)=default
Move-assign the wrapped object from another wrapper.
MoveByCopy & operator=(const MoveByCopy &other)
Copy-assign by moving the wrapped object out of the source wrapper.
Definition move_by_copy.h:69
T move_type
Wrapped type moved through copy-shaped APIs.
Definition move_by_copy.h:24
MoveByCopy(move_type &&to_move)
Store a move-only value for transfer through copy-only call sites.
Definition move_by_copy.h:35
MoveByCopy(MoveByCopy &&other)=default
Move the stored object from another wrapper.
Contains utilities for moving objects by copying them.
Definition move_by_copy.h:13
MoveByCopy< T > const_cmove(const T &movable)
Copy-shape wrapper for moving from a const reference.
Definition move_by_copy.h:104
MoveByCopy< T > cmove(T &movable)
Copy a move-only value by moving from the source reference.
Definition move_by_copy.h:92