On Thu, May 9, 2013 at 10:14 PM, Andrei Alexandrescu <
seewebsiteforem...@erdani.org> wrote:

> On 5/9/13 10:05 PM, Steven Schveighoffer wrote:
>
>> On Thu, 09 May 2013 21:47:14 -0400, Andrei Alexandrescu
>> <seewebsiteforem...@erdani.org**> wrote:
>>
>>  On 5/9/13 4:36 PM, Peter Alexander wrote:
>>>
>>>> I'm not sure about how common it is, but I really don't like the idea of
>>>> calls like swap(1, 2) being legal. Seems like a step backward from C++.
>>>>
>>>
>>> I think if we ever get swap(1, 2) to compile and run we'd effectively
>>> have destroyed the D programming language.
>>>
>>
>> Depends on context.
>>
>> int swap(int diskNum, int partitionNum);
>>
>> Someone pointed out that swap could be a function that swaps heap
>> indexes, and might even take by ref not caring if you want the resulting
>> value that was swapped.
>>
>> with(someHeap)
>> {
>> swap(1, 2); // swap indexes 1 and 2
>> }
>>
>> -Steve
>>
>
> Now that's great trolling!
>

To clear my name, just in case: I wasn't trolling. I have a use case (in a
heap implementation):

    void indexSwap(ref int a, ref int b) {
       swap(array[a], array[b]);
       swap(a, b);
    }

It would be great to be able to call indexSwap(index, index*2 + 1) in one
line without having to create a named temporary for the second argument,
and with having it mutate index to be index*2 + 1. I think auto ref solves
it, though a call-site solution (an inline way to create that temporary)
seems like it would work too.

Dmitry

Reply via email to