Function adapters, currying: how to build a generalized binder?

  • Thread starter Giovanni Gherdovich
  • Start date
G

Giovanni Gherdovich

Hello,

as you know the algorithm std::accumulate in the
version

template<class In, class T, class BinOp>
T accumulate(In first, In last, T init, BinOp op)
{
while(first != last) init = op(init,*first++);
return init;
}

(from the header <numeric>) requires a binary function
as third argument.

Well, consider if I have a function object like this

struct some_operation
{
double operator()(double x, double y, double z)
{
return sin( pow(x*y,2) * z); // or any operation you like
}
}

I would like to bind, say, the first argument x to
a fixed value, then make a binary function out of my
ternary function some_operation, and provide it to
the algorithm std::accumulate.

Is there any standard way to do such binding?
I know the function adapters std::bind1st and std::bind2nd,
but thay work only for binary functions and yeld unary
functions...
Is there any way to use these two binders to build
more general binders?

Best regards,
Giovanni Gh.
 
G

gpderetta

[...]
Is there any standard way to do such binding?

Check boost.bind, which will also be in the next standard.
I know the function adapters std::bind1st and std::bind2nd,
but thay work only for binary functions and yeld unary
functions...
Is there any way to use these two binders to build
more general binders?

I do not think so, and anyways, any solution involving the (current)
standard binders will easily drive you insane :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top