libzed 1.10.2
A general-purpose library for quick and simple data manipulation.
 
Loading...
Searching...
No Matches
generatorSentinel.cpp
// This example shows usage of the range generator with a custom sentinel.
#include <iostream>
#include <z/all.hpp>
int main() {
std::cout << "Generating even numbers until they're divisible by 20" << std::endl;
// Generate numbers until the next number would be divisible by 20 (ignoring zero).
sentinel untilDivisibleBy20([](long value, long stepSize) -> bool { return value && value % 20 == 0; });
auto even = range(0, untilDivisibleBy20, 2);
for (auto i : even) {
std::cout << i << std::endl;
}
}
A sentinel that stops a numeric generator when the value reaches a certain point.
Definition sentinel.hpp:10
generator< long, long > range(long begin, long end, long step=1) noexcept
Generate a sequence of integers in a specified range.