Skip to content

Commit

Permalink
& for generator::begin
Browse files Browse the repository at this point in the history
  • Loading branch information
kelbon committed Aug 12, 2023
1 parent b10cbb7 commit a6a9e1a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion include/async_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ struct async_task {
now = cur_state.load(std::memory_order::acquire);
}
}
// TODO try_wait / get

// postcondition - handle_ == nullptr
Result get() &&
requires(!std::is_void_v<Result>)
Expand All @@ -84,7 +86,7 @@ struct async_task {

auto result = *std::move(handle_.promise().storage);
// result always exist, its setted or std::terminate called on exception.
handle_.destroy();
std::exchange(handle_, nullptr).destroy();
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion include/generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ struct generator {
// * if .empty(), then begin() == end()
// * produces next value(often first)
// iterator invalidated only when generator dies
iterator begin() [[clang::lifetimebound]] {
iterator begin() & [[clang::lifetimebound]] {
if (!empty()) [[likely]] {
top.promise()._current_result_ptr = &current_result;
top.promise().current_worker.resume();
Expand Down

0 comments on commit a6a9e1a

Please sign in to comment.