D2's std.algorithm

Craig Black cblack at ara.com
Tue Dec 11 09:57:18 PST 2007


"Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message 
news:fjl4fo$8am$1 at digitalmars.com...
> >   sort!("a > b")(array);
>
> I just wanted to say that this is BRILLIANT!  Zero call overhead, zero 
> syntax overhead, compile-time lambda functions!
>
> All the algorithms should support this syntax so we can do sexy 
> compile-time lambda one-liners like:
>
>    find!("a.some_member > 10")(array);
>
> or
>
>    partition!("a.call_something() !is null")(array);
>
> etc.
>
> And probably those should allow a data arg passed as 'b' to the lambda 
> function so you could do something like
>    find!("a.some_member > b")(array, 10);
>
> Or even use template varargs and number the args automatically to allow:
>
>    find!("a.x > b && a.w < c")(array, 10, 20);
>
> It would just sequentially name the arguments b,c,d,e... etc.
>
> Or even make it like C#/Tango's format string patterns since the string 
> can be processed before mixing it in.
>    find!("a.x > {1} && a.w < {2}")(array, 10, 20);
>
> That would be excellent.  Take that boost::lambda!
>
> --bb

Yes very cool!  Would be even better if the parens could be removed. 
Ideally, the compiler would be able to do CTFE with some lambdas.

-Craig 





More information about the Digitalmars-d mailing list