От: | Evgeny.Panasyuk | ||
Дата: | 08.06.15 20:49 | ||
Оценка: |
V>и только у меня созрел полный возмущения вопрос: а как он думает оформлять останов???V>4 Writing simple generators
V>Consider a simple generator that counts down from a specified starting value:
V>V>auto g = [n = int(10)]() resumable V>{ V> std::cout << "Counting down from " << n << "\n"; V> while (n > 0) V> { V> yield n; V> n -= 1; V> } V>}; V>
V>Улыбнуло.V>Instead of returning a single value as in a normal lambda, we generate a sequence of values
V>using the yield statement. To obtain these values we call the generator as a normal function
V>object:
V>V>try V>{ V>for (;) V>std::cout << g() << “\n”; V>} V>catch (std::stop_iteration&) V>{ V>} V>
и приводит другие варианты.However, in many use cases an exception will not be acceptable. To avoid the exception we need to prevent the generator from falling off the end.