template <class T>
template <class F>
-void Promise<T>::fulfil(const F& func) {
- fulfilHelper(func);
+void Promise<T>::fulfil(F&& func) {
+ fulfilHelper(std::forward<F>(func));
}
template <class T>
typename std::enable_if<
std::is_convertible<typename std::result_of<F()>::type, T>::value &&
!std::is_same<T, void>::value>::type
-inline Promise<T>::fulfilHelper(const F& func) {
+inline Promise<T>::fulfilHelper(F&& func) {
throwIfFulfilled();
try {
setValue(func());
typename std::enable_if<
std::is_same<typename std::result_of<F()>::type, void>::value &&
std::is_same<T, void>::value>::type
-inline Promise<T>::fulfilHelper(const F& func) {
+inline Promise<T>::fulfilHelper(F&& func) {
throwIfFulfilled();
try {
func();
p.fulfil([] { do something that may throw; return a T; });
*/
template <class F>
- void fulfil(const F& func);
+ void fulfil(F&& func);
private:
typedef typename Future<T>::objPtr objPtr;
typename std::enable_if<
std::is_convertible<typename std::result_of<F()>::type, T>::value &&
!std::is_same<T, void>::value>::type
- fulfilHelper(const F& func);
+ fulfilHelper(F&& func);
template <class F>
typename std::enable_if<
std::is_same<typename std::result_of<F()>::type, void>::value &&
std::is_same<T, void>::value>::type
- fulfilHelper(const F& func);
+ fulfilHelper(F&& func);
};
}}