19 Eylül 2017 Salı

coroutine push_type Sınıfı

Giriş
Şu satırı dahil ederiz.
#include <boost/coroutine2/all.hpp>
Tanımlama
Şöyle yaparız.
using Coroutine_t = boost::coroutines2::coroutine<int>::push_type;
operator() metodu
Örnek
Şöyle yaparız.
#include <boost/coroutine2/all.hpp>

#include <iostream>
#include <cassert>

int main() {
  auto sum = 0;
  using Coroutine_t = boost::coroutines2::coroutine<int>::push_type;
  auto coro = Coroutine_t{[&](auto& yield) {
    for (;;) {
      auto val = yield.get();
      std::cout << "Currently " << val << std::endl;
      sum += val;
      yield(); // jump back to starting context
    }
  }};

  std::cout << "Transferring 1" << std::endl;
  coro(1); // transfer {1} to coroutine-function
  std::cout << "Transferring 2" << std::endl;
  coro(2); // transfer {1} to coroutine-function

}

Hiç yorum yok:

Yorum Gönder