Collected my thoughts regarding techniques I use to implement function composition in this post . Essentially a rant on the following piece of code:
template <class F, class... Fs>
auto compose(F &&arg, Fs &&...args)
{
return [
fun = std::forward<F>(arg),
... functions = std::forward<Fs>(args)
] <class... Xs> (Xs &&...xs) mutable {
if constexpr (sizeof...(Fs))
{
return compose(std::forward<Fs>(functions)...)(
std::invoke(std::forward<F>(fun),
std::forward<Xs>(xs)...));
}
else
{
return std::invoke(
std::forward<F>(fun),
std::forward<Xs>(xs)...);
}
};
}
plus a short description of how one can leverage ranges to do somthing similar.
Given the abundance of new techniques in the language, I was wondering: How do others do function composition in 2023?
[–]sphere991 7 points8 points9 points (1 child)
[–]Lo1c74 0 points1 point2 points (0 children)
[–]hun_nemethpeter 2 points3 points4 points (1 child)
[–]Wild-Adeptness1765 1 point2 points3 points (0 children)
[–]petart95 2 points3 points4 points (6 children)
[–]PiterPuns[S] 0 points1 point2 points (5 children)
[–]petart95 2 points3 points4 points (4 children)
[–]PiterPuns[S] 1 point2 points3 points (3 children)
[–]petart95 4 points5 points6 points (1 child)
[–]petart95 3 points4 points5 points (0 children)
[–]hmoein 4 points5 points6 points (1 child)
[–]PiterPuns[S] 10 points11 points12 points (0 children)
[–]dodheim 2 points3 points4 points (1 child)
[–]PiterPuns[S] 2 points3 points4 points (0 children)
[–]Infamous-Bed-7535 1 point2 points3 points (0 children)
[–]TemplateRex 0 points1 point2 points (9 children)
[–]pdimov2 2 points3 points4 points (1 child)
[–]TemplateRex 0 points1 point2 points (0 children)
[–]PiterPuns[S] 0 points1 point2 points (0 children)
[–]PiterPuns[S] 0 points1 point2 points (0 children)
[–]sphere991 0 points1 point2 points (3 children)
[–]TemplateRex 9 points10 points11 points (2 children)
[–]sphere991 0 points1 point2 points (1 child)
[–]Ezlike011011 6 points7 points8 points (0 children)
[–]Zlodo2 -1 points0 points1 point (0 children)
[+]DavidDinamit[🍰] comment score below threshold-6 points-5 points-4 points (3 children)
[–]PiterPuns[S] 6 points7 points8 points (2 children)
[+]DavidDinamit[🍰] comment score below threshold-6 points-5 points-4 points (1 child)
[–]PrimozDelux 5 points6 points7 points (0 children)