start | find | index | login or register | edit | ||
2009-07-06
by earl, 5627 days ago
Sometimes, being accumulate(I->begin(), I->end(), 0, compose2(plus<int>(), Update: the above is nonsense (as in: won't compile). Problem is, compose2 composes one binary and two unary functions such that:
What I want/need is a similar functional F such that:
Any hints? How'd you call that, does it exist already? I know about Boost's rather versatile bind , but that doesn't meet the point-free criterion.Update: In lack of a better name, let's call it compose3 :#include <functional> Now if we replace compose2 with compose3 in the original example, it will compile and work as expected/desired.For illustration purposes, the same thing in Haskell: compose3 :: (a -> b -> c) -> (u -> a) -> (v -> b) -> u -> v -> c Finally, let's let go of the insane hiding of points, but simply use lambdas (using boost::bind for the C++ version): C++: If we relax things further, to allow a temporary vector being created, this simply collapses to: Haskell: Which concisely describes what the original piece of code was intended to achieve: sum a list element-wise transformed by a function. |
search 4 active users
backlinks (more) none, yet recent stores (more) recent comments echo earlZstrainYat|tr ZY @. |
|
earl.strain.at • esa3 • online for 8676 days • c'est un vanilla site |