Daily C++ Tip 4
A lazy pipeline with std::generator
A generator coroutine produces values only when the caller iterates.
A coroutine returning std::generator produces values on demand: nothing runs until the caller iterates, and nothing is stored.
#include <generator>
#include <iostream>
// Lazy: nothing runs until the caller iterates.
std::generator<int> evens(int upto) {
for (int i = 0; i < upto; i += 2) co_yield i;
}
int main() {
for (int v : evens(10)) std::cout << v << ' ';
std::cout << '\n';
}
Observed output:
0 2 4 6 8
Facts verified 2026-11-04. The code on this page was compiled and run on the box with GCC 16.2.0 at -std=c++23 -Wall -Wextra; the outputs quoted are the observed outputs. MSVC was not tested.
Keep Exploring
Keep exploring the docs, samples, and free tools to continue your evaluation.
Free Checker
Run the free domain trust checker
Score SPF, DKIM, DMARC, MTA-STS, TLS-RPT, and BIMI for any domain.
Samples
Inspect sample output
Review grounded audit, compare, fix-plan, and report excerpts before you wire the API into anything.
Reference
Move into the docs
Jump from the workflow page into the quickstart, endpoint guides, and full OpenAPI reference.