#include "stdafx.h"
#include <experimental\generator>
#include <experimental\coroutine>
#include <iostream>
#include <string>
#include <numeric>
using namespace std;
using namespace std::experimental;
std::experimental::generator<int> gen()
{
for (int i = 0;; ++i)
co_yield i;
};
std::experimental::generator<int> take_until(std::experimental::generator<int> g, int sentinel)
{
for (auto v : g)
{
if (v == sentinel)
break;
co_yield v;
}
}
int main()
{
auto g1 = take_until(gen(), 10);
auto a = std::accumulate(g1.begin(), g1.end(), 0);
cout << a << endl;
std::string s;
getline(cin, s);
return 0;
}
Monday, October 24, 2016
generator pipeline and accumulate
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment