Код: Выделить всё
struct BSCoroutineHandler {
struct promise_type {
int value;
BSCoroutineHandler get_return_object() {
return {.h_ = std::coroutine_handle
::from_promise(*this)};
}
std::suspend_never initial_suspend() { return {}; }
std::suspend_always final_suspend() noexcept { return {}; }
void return_value(int v) { value = v; }
void unhandled_exception() { std::terminate(); }
};
std::coroutine_handle h_;
int get() { return h_.promise().value; }
void resume() { this->h_.resume(); }
bool done() { return this->h_.done(); }
};
BSCoroutineHandler binarySearchCoroutine(int *arr, int target,
const int arr_size) {
int low = 0, high = arr_size - 1;
while (low
Подробнее здесь: [url]https://stackoverflow.com/questions/79217388/are-there-more-efficient-awaiters-for-c-coroutines-than-stdsuspend-always[/url]