Make future return reference instead of value
This commit is contained in:
parent
0210b61540
commit
5c0d4d8d29
1 changed files with 14 additions and 2 deletions
|
|
@ -40,6 +40,18 @@ namespace psemek::async
|
|||
using type = util::function<void()>;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct future_result_type
|
||||
{
|
||||
using type = T &;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct future_result_type<void>
|
||||
{
|
||||
using type = void;
|
||||
};
|
||||
|
||||
struct cancel_token
|
||||
{};
|
||||
|
||||
|
|
@ -139,7 +151,7 @@ namespace psemek::async
|
|||
return has_value_unsafe();
|
||||
}
|
||||
|
||||
T get()
|
||||
typename detail::future_result_type<T>::type get()
|
||||
{
|
||||
if (!state_)
|
||||
throw empty_future_error{};
|
||||
|
|
@ -151,7 +163,7 @@ namespace psemek::async
|
|||
if constexpr (std::is_same_v<T, void>)
|
||||
return;
|
||||
else
|
||||
return std::move(*(state_->value));
|
||||
return *(state_->value);
|
||||
}
|
||||
else
|
||||
std::rethrow_exception(state_->exception);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue