Closed tcbrindle closed 1 year ago
Patch coverage: 95.83
% and project coverage change: +0.04
:tada:
Comparison is base (
4b20127
) 98.33% compared to head (79bfe39
) 98.37%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
CodeCov isn't happy, but I think that's because we've removed some lines that were hit in pqdsort.hpp, so the few that we miss now count for a greater percentage of the total
I like projections in std::ranges. But they come don't come for free: there is a (small?) overhead in terms of compile times, and an added burden in terms of specification, concept formulation and documentation.
What this PR does is add two new function adaptors/combinators which provide the equivalent functionality to projection arguments to algorithms, but in an opt-in basis. So instead of saying, for example
you now say
This arguably makes it more clear what's actually happening -- that we're modifying the comparator function object.
The
proj
adaptor takes an n-ary callableF
and a unary projectionP
and returns a new n-ary callable which, when invoked with argumentsargs...
, callsF(P(args)...)
-- that is, it applies the projection to each argument before callingF
.This covers most uses of projections in the library. The exceptions are algorithms which take two sequences and two (different) projections --
equal()
andcompare()
for example. For this case we have another adaptorproj2
(which should really be calledbinary_project
or something like that, but it's a bit too long). This takes a binary callableF
and two unary projectionsL
andR
, and constructs a binary callable which, when invokes with argumentsa
andb
callsF(L(a), R(b))
-- that is, it applies the left and right projection functions to the left and right arguments. (Theoretically we could make it all variadic and have N projections for an n-ary callable, but we only ever need two in Flux.)Both
proj
andproj2
are actually aggregate classes used via CTAD, meaning you can use designated initialisers to say, for examplewhich I actually think reads quite well.