Pavel Novikov - "Understanding Coroutines by Example" - C++ London

Поделиться
HTML-код
  • Опубликовано: 13 янв 2025

Комментарии • 8

  • @SamWhitlock
    @SamWhitlock 3 года назад

    11:21 I know this is a simplification in the presentation, but this needs to be `return { coroutine_handle::from_promise(*this); }`. That effectively does the same thing, but it returns the coro handle (which the Task needs to hang on to as a member variable to preserve the coro).

    • @PaulSkeptic
      @PaulSkeptic 3 года назад +1

      That's the other way to implement it. Coroutine handle and reference to promise are basically synonyms: having one you can trivially get the other (unless the coroutine handle is type erased like this: *std::coroutine_handle* ).
      In this case it was easier to use a pointer to promise instead of coroutine handle since *Promise* exposes functionality that the *Task* implementation can access directly without converting a coroutine handle to a reference to promise every time.

    • @SamWhitlock
      @SamWhitlock 3 года назад +1

      @@PaulSkeptic Ah yes this makes sense. I'm still rewatching this presentation every week or so to learn a little more each time :D

  • @w-mwijnja8919
    @w-mwijnja8919 3 года назад +2

    I very much enjoyed your Robert C. Weide joke at the beginning! :-D

  • @SamWhitlock
    @SamWhitlock 3 года назад

    10:12 shouldn't this custom deleter also call `delete on the Promise pointer too?

    • @PaulSkeptic
      @PaulSkeptic 3 года назад +1

      Promise "lives" inside the coroutine frame, so calling *.destroy()* on the coroutine _handle_ effectively destroys the coroutine frame _and_ the promise, freeing all the resources used by the coroutine.

  • @MaceUA
    @MaceUA 3 года назад

    12:50 - can we just write `U&&` instead of that complex `decltype(...)` expression?

    • @PaulSkeptic
      @PaulSkeptic 3 года назад +1

      Yes, you absolutely can.
      Expression inside decltype is just a copypaste of the expression in initialization.