Summary: Unit is a bit special because it's just something special to use instead of `Promise<void>`, so let's offer the same sugar that `Promise<void>` has (`p.setValue()` instead of `p.setValue(Unit())`)
Test Plan: New unit tests. Look, a pun!
Reviewed By: jsedgwick@fb.com
Subscribers: exa, folly-diffs@, jsedgwick, yfeldblum, chalfant, davejwatson, hannesr
FB internal diff:
D2014139
Tasks:
6847876
Signature: t1:
2014139:
1430159950:
1484ee420c6d7f0f794a546b78ef1601c2eec45c
setTry(Try<T>(std::forward<M>(v)));
}
-template <class T>
-void Promise<T>::setValue() {
- static_assert(std::is_same<T, void>::value,
- "Use setValue(value) instead");
-
- setTry(Try<void>());
-}
-
template <class T>
template <class F>
void Promise<T>::setWith(F&& func) {
/// handled.
void setInterruptHandler(std::function<void(exception_wrapper const&)>);
- /** Fulfill this Promise (only for Promise<void>) */
- void setValue();
+ /// Fulfill this Promise<void>
+ template <class B = T>
+ typename std::enable_if<std::is_void<B>::value, void>::type
+ setValue() {
+ setTry(Try<T>());
+ }
+
+ /// Sugar to fulfill this Promise<Unit>
+ template <class B = T>
+ typename std::enable_if<std::is_same<Unit, B>::value, void>::type
+ setValue() {
+ setTry(Try<T>(T()));
+ }
/** Set the value (use perfect forwarding for both move and copy) */
template <class M>
EXPECT_TRUE(collect(fs2).isReady());
}
+
+TEST(Promise, defaultConstructedUnit) {
+ Promise<Unit> p;
+ p.setValue();
+}