74 for (
long n = 0; ; ++n)
80 std::cout <<
"[1] Laziness: an infinite sequence, truncated on demand\n";
83 std::cout <<
"First 5 multiples of 7, taken from an unbounded generator:\n";
91 std::cout <<
" " << n <<
"\n";
95 std::cout <<
"Candidates examined before stopping: " <<
checked <<
"\n";
96 std::cout <<
"The generator function never runs past that point — there is\n"
97 "no way to \"materialize\" natural_numbers() into a container.\n\n";
105 size_t i = (
tok[0] ==
'+' or tok[0] ==
'-') ? 1 : 0;
108 for (; i <
tok.size(); ++i)
109 if (
not std::isdigit(
static_cast<unsigned char>(
tok[i])))
126 for (
const std::string &
tok : tokens)
129 <<
"not a valid integer: \"" <<
tok <<
"\"";
137 std::cout <<
"[2] Exception propagation across suspension points\n";
140 const std::vector<std::string> tokens = {
"10",
"20",
"30",
"oops",
"40"};
141 std::cout <<
"Parsing tokens: 10, 20, 30, oops, 40\n";
148 std::cout <<
" parsed " << v <<
"\n";
152 catch (
const std::invalid_argument &e)
154 std::cout <<
" caught: " << e.what() <<
"\n";
156 std::cout <<
"Sum of values parsed before the error: " <<
sum <<
" (expect 60)\n";
157 std::cout <<
"The three valid tokens were already consumed and summed; the\n"
158 "exception surfaced exactly where the fourth co_yield would\n"
159 "have been, just like a hand-written iterator would throw.\n\n";
178 std::cout <<
"[3] Composition: chaining lazy stages\n";
181 std::cout <<
"squared(evens_only(natural_numbers())), first 6 values:\n";
185 std::cout <<
" " << v <<
"\n";
189 std::cout <<
"Expect: 0, 4, 16, 36, 64, 100 — each stage only pulls as\n"
190 "many values from its source as the next stage asks for.\n\n";
196 std::cout <<
"\n=== Aleph::Generator<T>: lazy sequences ===\n\n";
202 std::cout <<
"Done.\n";
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
Lazy sequence type (Aleph::Generator<T>) built on C++20 coroutines.
size_t size_t int32_t value
Lazy, single-pass sequence of T values produced by a coroutine.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
void print_rule()
Prints a horizontal rule for example output separation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.