title: C++20 coroutines: Why is the promise type seperated from the coroutine object?
body: <p>A typical coroutine object looks like this:</p>
  <pre class="lang-cpp prettyprint-override"><code>struct Coroutine
  {
      struct promise_type
      {
          int value;
          Coroutine get_return_object() {return this; }
          std::suspend_never initial_suspend() { return {}; }
          std::suspend_never final_suspend() noexcept { return {}; }
          void return_value(int v) {
              value = v;
          }
          void unhandled_exception() {};
      };
  
      Coroutine(promise_type *p) : handle(std::coroutine_handle&lt;promise_type&gt;::from_promise(*p)) {
      };
  
      ~Coroutine() {
          handle.destroy();
      }
  
      std::coroutine_handle&lt;promise_type&gt; handle;
  };
  </code></pre>
  <p>Why is the <code>promise_type</code> separated from the coroutine. Does it make sense to have multiple coroutines for a single promise, or multiple promises for a single coroutine? Is there a use case for that?</p>
  <p>Because otherwise, if only one promise can exist per coroutine, wouldn't it have been enough to embed the return value into the <code>Coroutine</code> structure, e. g.:</p>
  <pre class="lang-cpp prettyprint-override"><code>struct Coroutine
  {
     int value;
     std::suspend_never initial_suspend() { return {}; }
     std::suspend_never final_suspend() noexcept { return {}; }
     void return_value(int v) {
         value = v;
     }
     void unhandled_exception() {};
  };
  </code></pre>