CKTIS / C++
Data processing pipelines
A pipeline divides data processing into successive stages. In C++, range adaptors let you compose filtering and transformation with operator |, while the resulting view computes values lazily during iteration.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
source | std::views::filter(predicate) | std::views::transform(function)Data processing pipelines connect a data source, successive operations, and a consumer of the result. In the C++ ranges library, operator | connects adaptors into a pipeline; here it does not mean a bitwise operation on the elements.
std::views::filter(predicate) keeps elements satisfying the predicate, while std::views::transform(function) exposes the results of applying the function to elements. Stage order matters: filtering before transformation tests the source values, whereas filtering afterward tests the transformed values.
The result is a lazy view, not a container of precomputed intermediate results. Work happens during iteration. In the example, the loop consumes the view and sums the squares of the even numbers: 4 + 16 + 36, giving 56.
A view can refer to existing data. Here, pipeline uses values, so values must remain alive throughout use of the pipeline; do not return such a view referring to a local array.
The example targets compilation in C++23 mode. The supplied link points to an evolving working draft, not a frozen C++23 edition. A repository compiler flag does not attest the production runtime environment.
Examples
#include <array>
#include <iostream>
#include <ranges>
int main() {
const std::array<int, 6> values{1, 2, 3, 4, 5, 6};
auto pipeline = values
| std::views::filter([](int x) { return x % 2 == 0; })
| std::views::transform([](int x) { return x * x; });
int total = 0;
for (int x : pipeline) {
total += x;
}
std::cout << total << '\n';
}
Result
56
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.