D2's std.algorithm

Sean Kelly sean at f4.ca
Tue Dec 18 16:49:42 PST 2007


Bill Baxter wrote:
> 
> D2 std.algorithm.sort actually does come in two flavors, the string kind 
> and an alias kind.
> 
> And in fact the string kind just creates a function that's passed to the 
> alias kind.  So it probably doesn't actually eliminate the call overhead 
> despite the comparison function being available at compile time.  I was 
> a little surprised when I saw that implementation, actually.

If I had to guess I'd say it's to make the routines CTFE-able.  But I 
don't feel it's as flexible as the method used by Tango (and roughly 
illustrated in my previous post).

> Anyway, I just like the idea of using a string literal for comparisons 
> for the simple cases.  I tried to use boost::functional once and was 
> totally incapable of writing something as trivial as an expression that 
> used .member of the argument thingy rather than the argument itself. But 
> the string expression makes it completely obvious how to do that. And it 
> *should* be inline-able and CTFE-able if you write your templates 
> carefully, even if the current implementation is not*.

I very much agree.

> * Note that I'm not sure if the std.algorithm implementation is 
> CTFE-able or not.  Haven't tried it.  Doesn't look like it would be 
> though. Not by DMD at least.

The routines in tango.core.Array are CTFE-able but for the issue 
described here:

http://d.puremagic.com/issues/show_bug.cgi?id=1742

So I imagine those in std.algorithm are as well, or could be made so 
with little effort.


Sean



More information about the Digitalmars-d mailing list