Skip to content

Commit

Permalink
Merge pull request #125 from accelerated/master
Browse files Browse the repository at this point in the history
Added varargs to support non-default-constructible types in the Promi…
  • Loading branch information
safaruqi authored Feb 15, 2020
2 parents 4376587 + 4575c73 commit 7fa1f25
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions quantum/impl/quantum_promise_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ int ICoroPromise<PROMISE, T>::closeBuffer()
#endif

template <class T>
Promise<T>::Promise() :
template <class...ARGS>
Promise<T>::Promise(ARGS&&...args) :
IThreadPromise<Promise, T>(this),
ICoroPromise<Promise, T>(this),
_sharedState(new SharedState<T>()),
_sharedState(new SharedState<T>(std::forward<ARGS>(args)...)),
_terminated(false)
{}

Expand Down
5 changes: 3 additions & 2 deletions quantum/impl/quantum_shared_state_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ namespace quantum {
// class SharedState
//==============================================================================================
template <class T>
SharedState<T>::SharedState() :
template <class...ARGS>
SharedState<T>::SharedState(ARGS&&...args) :
_state(FutureState::PromiseNotSatisfied),
_value(T())
_value(T(std::forward<ARGS>(args)...))
{
}

Expand Down
3 changes: 2 additions & 1 deletion quantum/quantum_promise.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class Promise : public IPromiseBase,
using Ptr = std::shared_ptr<Promise<T>>;

//Constructor
Promise();
template <class...ARGS>
Promise(ARGS&&...args);

//Move constructor
Promise(Promise<T>&& other) :
Expand Down
3 changes: 2 additions & 1 deletion quantum/quantum_shared_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class SharedState
int setException(ICoroSync::Ptr sync,
std::exception_ptr ex);
private:
SharedState();
template <class...ARGS>
SharedState(ARGS&&...args);

void conditionWait() const;

Expand Down

0 comments on commit 7fa1f25

Please sign in to comment.