opStar

David B. Held dheld at codelogicconsulting.com
Tue Nov 13 22:44:23 PST 2007


Janice Caron wrote:
> On Nov 13, 2007 6:17 AM, David B. Held <dheld at codelogicconsulting.com> wrote:
>> int size[3] = { length, width, height };
>> std::sort(size + 0, size + 3);
>>
>> I do lots of little stuff like this, which is very convenient.
> 
> In D:
> 
>     size.sort;
> 
> Pointers not needed.

This presumes that the builtin sort knows the ordering I want to use. 
Let's try this:

Customer[] list = { Jim, Bob, Fred };
list.sort;

Does list get sorted by first name, last name, phone number, SSN, 
favorite color, or uncle's friend's dog's favorite park?  If I want to 
define a custom sort that takes an ordering, I can't use the builtin. 
Now, in D, arrays are first-class objects, so I would just take an array 
directly...unless I wrote a generic sort algorithm that took iterators 
instead.  Then I would rather pass array-iterators to the sort algorithm.

Dave



More information about the Digitalmars-d mailing list