Description
Suggestion
Cpp2 could support the pipeline operator |>
as proposed in P2011 and further explored in P2672.
Specifically, the pipeline operator with the "placeholder model" with mandatory placeholder (e.g. $
), as described in P2672 section 6 Disposition
. Both papers explain the problem and motivation for the new operator, as well as discussing options for the placeholder token.
Circle uses $
as its token.
The proposed operator enables a simpler left-to-right style as opposed to an inside-out style.
Conor Hoekstra (code_report) has various talks about ranges and pipelines and explains how the pipeline operator can make the code simpler and more readable. The following is one of his examples:
Without the operator:
auto filter_out_html_tags(std::string_view sv) {
auto angle_bracket_mask =
sv | rv::transform([](auto e) { return e == '<' or e == '>'; });
return rv::zip(rv::zip_with(std::logical_or{},
angle_bracket_mask,
angle_bracket_mask | rv::partial_sum(std::not_equal_to{})), sv)
| rv::filter([](auto t) { return not std::get<0>(t); })
| rv::transform([](auto t) { return std::get<1>(t); })
| ranges::to<std::string>;
}
With the operator:
auto filter_out_html_tags(std::string_view sv) {
return sv
|> transform($, [](auto e) { return e == '<' or e == '>'; })
|> zip_transform(std::logical_or{}, $, scan_left($, true, std::not_equal_to{}))
|> zip($, sv)
|> filter($, [](auto t) { return not std::get<0>(t); })
|> values($)
|> ranges::to<std::string>($);
}
Will your feature suggestion eliminate X% of security vulnerabilities of a given kind in current C++ code?
No
Will your feature suggestion automate or eliminate X% of current C++ guidance literature?
No
Describe alternatives you've considered.
Alternatives are discussed at length in the two papers referenced above.