proxygen
RValueReferenceWrapper.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017-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 <cassert>
20 #include <memory>
21 #include <utility>
22 
23 namespace folly {
24 
41 template <class T>
43  public:
44  using type = T;
45 
51 
57  : ptr_(std::addressof(ref)) {}
58 
62  explicit rvalue_reference_wrapper(T&) noexcept = delete;
63 
68  : ptr_(other.ptr_) {
69  other.ptr_ = nullptr;
70  }
71 
77  ptr_ = other.ptr_;
78  other.ptr_ = nullptr;
79  return *this;
80  }
81 
85  /* implicit */ operator T &&() && noexcept {
86  return static_cast<rvalue_reference_wrapper&&>(*this).get();
87  }
88 
92  T&& get() && noexcept {
93  assert(valid());
94  T& ref = *ptr_;
95  ptr_ = nullptr;
96  return static_cast<T&&>(ref);
97  }
98 
103  template <class... Args>
104  decltype(auto) operator()(Args&&... args) &&
105  noexcept(noexcept(std::declval<T>()(std::forward<Args>(args)...))) {
106  return static_cast<rvalue_reference_wrapper&&>(*this).get()(
107  std::forward<Args>(args)...);
108  }
109 
114  return ptr_ != nullptr;
115  }
116 
117  private:
118  // Disallow copy construction and copy assignment, to make it harder to
119  // accidentally use an rvalue reference multiple times.
122 
123  T* ptr_;
124 };
125 
148 template <typename T>
151 }
152 template <typename T>
154 } // namespace folly
rvalue_reference_wrapper(rvalue_reference_wrapper< T > &&other) noexcept
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
STL namespace.
rvalue_reference_wrapper & operator=(rvalue_reference_wrapper &&other) noexcept
folly::std T
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
requires E e noexcept(noexcept(s.error(std::move(e))))
rvalue_reference_wrapper< T > rref(T &&value) noexcept
const
Definition: upload.py:398
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)