Commit bc847809 authored by Hans Fugal's avatar Hans Fugal Committed by Alecs King

makeMoveWrapper(lvalue)

Summary: Because why not?

Test Plan: new unit tests

Reviewed By: hannesr@fb.com

Subscribers: trunkagent, exa, folly-diffs@, yfeldblum, marccelani

FB internal diff: D1866123

Signature: t1:1866123:1425331395:742369597757456e5925af55c5d4198b607126f1
parent 66a07640
...@@ -63,9 +63,12 @@ class MoveWrapper { ...@@ -63,9 +63,12 @@ class MoveWrapper {
mutable T value; mutable T value;
}; };
template <class T> /// Make a MoveWrapper from the argument. Because the name "makeMoveWrapper"
MoveWrapper<T> makeMoveWrapper(T&& t) { /// is already quite transparent in its intent, this will work for lvalues as
return MoveWrapper<T>(std::forward<T>(t)); /// if you had wrapped them in std::move.
template <class T, class T0 = typename std::remove_reference<T>::type>
MoveWrapper<T0> makeMoveWrapper(T&& t) {
return MoveWrapper<T0>(std::forward<T0>(t));
} }
} // namespace } // namespace
...@@ -34,4 +34,19 @@ TEST(makeMoveWrapper, NonEmpty) { ...@@ -34,4 +34,19 @@ TEST(makeMoveWrapper, NonEmpty) {
EXPECT_EQ(**p, 5); EXPECT_EQ(**p, 5);
} }
TEST(makeMoveWrapper, rvalue) {
std::unique_ptr<int> p;
makeMoveWrapper(std::move(p));
}
TEST(makeMoveWrapper, lvalue) {
std::unique_ptr<int> p;
makeMoveWrapper(p);
}
TEST(makeMoveWrapper, lvalue_copyable) {
std::shared_ptr<int> p;
makeMoveWrapper(p);
}
} // namespace } // namespace
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment