Summary: Without this tag type, it's impossible to use `Synchronized` with types like:
```
struct A {
A(int, const char*);
A(const A&) = delete;
A& operator=(const A&) = delete;
A(A&&) = delete;
A& operator=(A&&) = delete;
};
```
In-place construction solves this problem. Usage:
```
Synchronized a(construct_in_place, 5, "c");
```
Reviewed By: nbronson
Differential Revision:
D2610071
fb-gh-sync-id:
251fe8f8f6a2d7484dda64cf04dcacb998145230
explicit Synchronized(T&& rhs) noexcept(nxMoveCtor)
: datum_(std::move(rhs)) {}
+ /**
+ * Lets you construct non-movable types in-place. Use the constexpr
+ * instance `construct_in_place` as the first argument.
+ */
+ template <typename... Args>
+ explicit Synchronized(construct_in_place_t, Args&&... args)
+ : datum_(std::forward<Args>(args)...) {}
+
/**
* The canonical assignment operator only assigns the data, NOT the
* mutex. It locks the two objects in ascending order of their
>(lhs);
}
+/**
+ * Like std::piecewise_construct, a tag type & instance used for in-place
+ * construction of non-movable contained types, e.g. by Synchronized.
+ */
+struct construct_in_place_t {};
+constexpr construct_in_place_t construct_in_place{};
+
} // namespace folly
FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(std::basic_string);
testTimedSynchronizedWithConst<TypeParam>();
}
+TYPED_TEST(SynchronizedTest, InPlaceConstruction) {
+ testInPlaceConstruction<TypeParam>();
+}
+
}
EXPECT_EQ(result, input);
}
+struct NotCopiableNotMovable {
+ NotCopiableNotMovable(int, const char*) {}
+ NotCopiableNotMovable(const NotCopiableNotMovable&) = delete;
+ NotCopiableNotMovable& operator=(const NotCopiableNotMovable&) = delete;
+ NotCopiableNotMovable(NotCopiableNotMovable&&) = delete;
+ NotCopiableNotMovable& operator=(NotCopiableNotMovable&&) = delete;
+};
+
+template <class Mutex> void testInPlaceConstruction() {
+ // This won't compile without construct_in_place
+ folly::Synchronized<NotCopiableNotMovable> a(
+ folly::construct_in_place, 5, "a"
+ );
+}
+
#endif /* FOLLY_TEST_SYNCHRONIZEDTESTLIB_INL_H */
template <class Mutex> void testConstCopy();
+template <class Mutex> void testInPlaceConstruction();
+
#include <folly/test/SynchronizedTestLib-inl.h>
#endif /* FOLLY_TEST_SYNCHRONIZEDTESTLIB_H */