More improvements of functor implementation
Follow up to !4012: significantly reduce the amount of memory consumed by the compiler when compiling functors.
- Replace the non-trivial recursive
chain
implementation with a very neat (local!) binary right-fold expression, which avoids generating nested template instances. This changes thechain
implementation from being one of the most complicated bits of code to being (almost) the simplest. - Pass operators by value instead of by type so we can do constant propagation and avoid promoting constants to the
NumericalValue
functor, and instead bind them directly to the operator, simplifying the type generated for binary expressions such asM < 1600
by effectively changing them to unary predicates ( in effect, changeM < 1600
into (the logical equivalent to)(<1600) @ M
instead of< ( M, NumericalValue(1600) )
. - Prefer variadic lambda capture (when available) over capturing a
std::tuple
to reduce the compile time overhead ofstd::tuple
(see here for more information). - Introduce
Tuplet
- an extremely minimalstd::tuple
replacement implemented as a lambda with variadic capture . It only supportapply
, but if that is all that is needed, it is a drop-in replacement. It requires much less resources to compile thanstd::tuple
! - Use
Tuplet
(instead ofstd::tuple
) to carry the payload of composed functors (when available). - prefer
apply
with (local) lambda over explicit helpers withstd::index_sequence<I...>
arguments - fix (expensive) copy in RecSummary functor
Edited by Gerhard Raven