proxygen
MoveWrapper.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <memory>
20 
21 namespace folly {
22 
34 template <class T>
35 class MoveWrapper {
36  public:
39  MoveWrapper() = default;
40 
42  explicit MoveWrapper(T&& t) : value(std::move(t)) {}
43 
45  MoveWrapper(const MoveWrapper& other) : value(std::move(other.value)) {}
46 
48  MoveWrapper(MoveWrapper&& other) : value(std::move(other.value)) {}
49 
50  const T& operator*() const {
51  return value;
52  }
53  T& operator*() {
54  return value;
55  }
56 
57  const T* operator->() const {
58  return &value;
59  }
61  return &value;
62  }
63 
65  T&& move() {
66  return std::move(value);
67  }
68 
69  // If you want these you're probably doing it wrong, though they'd be
70  // easy enough to implement
71  MoveWrapper& operator=(MoveWrapper const&) = delete;
72  MoveWrapper& operator=(MoveWrapper&&) = delete;
73 
74  private:
75  mutable T value;
76 };
77 
83  return MoveWrapper<T0>(std::forward<T0>(t));
84 }
85 
86 } // namespace folly
MoveWrapper(T &&t)
Move a value in.
Definition: MoveWrapper.h:42
const T * operator->() const
Definition: MoveWrapper.h:57
PskType type
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
MoveWrapper(const MoveWrapper &other)
copy is move
Definition: MoveWrapper.h:45
STL namespace.
folly::std T
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
MoveWrapper(MoveWrapper &&other)
move is also move
Definition: MoveWrapper.h:48
T && move()
move the value out (sugar for std::move(*moveWrapper))
Definition: MoveWrapper.h:65
MoveWrapper< T0 > makeMoveWrapper(T &&t)
Definition: MoveWrapper.h:82
MoveWrapper()=default
const T & operator*() const
Definition: MoveWrapper.h:50
MoveWrapper & operator=(MoveWrapper const &)=delete