Skip to content

Commit 0264b41

Browse files
author
Chris Sullivan
committed
Adding move_on_copy factory header
1 parent 2253b3c commit 0264b41

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

include/move_on_copy.hh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
template <typename T>
2+
class move_on_copy {
3+
public:
4+
move_on_copy(T&& aValue)
5+
: value_(std::move(aValue)) {}
6+
move_on_copy(const move_on_copy& other)
7+
: value_(std::move(other.value_)) {}
8+
9+
move_on_copy& operator=(move_on_copy&& aValue) = delete;
10+
move_on_copy& operator=(const move_on_copy& aValue) = delete;
11+
12+
T& value() { return value_; }
13+
const T& value() const { return value_; }
14+
15+
private:
16+
mutable T value_;
17+
};
18+
19+
template <typename T>
20+
inline move_on_copy<T> make_move_on_copy(T&& aValue) {
21+
return move_on_copy<T>(std::move(aValue));
22+
}

0 commit comments

Comments
 (0)