C++: terser (shorter) lambda == SHORTY (ab-use?)
Published on: 2025-04-27 14:15:26
terser (shorter) lambda == SHORTY
This library is intended to give terser syntax than C++'s lambdas, not replace C++ with lazy DSL.
import shorty; using namespace shorty ::literals ; // you no longer need to remember if it's `std::less` or `std::greater` std::ranges::sort (subject, $lhs > $rhs); // filter only even subject | std::views::filter(($i % 2 ) == 0 ); // zip together and transform std::views::zip (A,B,C,D) | std::views::transform($a * $b + $c * $d); // call external function auto pythagorean = $($a * $a + $b * $b); // or $call; pythagorean ( 3.0 , 4.0 ) == 5.0; // casting auto to_int = $< int >($ 0 ); // or $cast; to_int ( 4.3 ) == 4; // remap by index auto indices = std::vector< int >{...}; auto mapping = indices | $(data)[$i];
accessing arguments
If shorty callable gets only one argument and the argument is tuple_like then it's automatically unwrapper. Same applies to any lazy calls.
By default arguments are accessible using $0 ... $9 syntax (for first
... Read full article.