On the richness of C++

MatBec bekkah at web.de
Wed Apr 16 12:40:20 PDT 2008


Jason House Wrote:

> The only thing I'm contesting is your statement that closures eliminate the need for a bind library.  While it's true they reduce the need for a bind library, they don't eliminate it.

Instead of call some strange bind function just create a closure taking the still unbound arguments that calles the function.


I'm not a d-Programmer, but in other languages this is very easy.

e.g. Haskell


foo x y z = x + y + z

bar f = f 9

-- Pass bar a version of foo wich has two arguments bound
bar \y -> foo 1 y 7


 
Or Ruby:


def foo (x, y, z)
   return x + y + z
end

def bar (f)
   return f(9)
end

bar |y| { foo(1, y, 7) }


Or in C#

int foo(int x, int y, int z)
{
   return x + y + z;
}

int bar (Func<int, int> f)
{
   return f(9);
}

bar(y => foo(1, y, 7));



Is C++'s bind realy any simpler?


int foo(int x, int y, int z)
{
   return x + y + z;
}

int bar (boost:function<int(int)> const & f)
{
   return f(9);
}

bar(boost::bind(foo, 1, _1, 7));



More information about the Digitalmars-d mailing list