Generic collection/element function signatures in D2 versus D1

Pelle pelle.mansson at gmail.com
Tue Sep 7 06:28:18 PDT 2010


On 09/07/2010 03:15 PM, Steven Schveighoffer wrote:
> On Tue, 07 Sep 2010 08:56:15 -0400, Jacob Carlborg <doob at me.com> wrote:
>
>> On 2010-09-07 14:49, Steven Schveighoffer wrote:
>>> On Sun, 05 Sep 2010 09:40:59 -0400, BLS <windevguy at hotmail.de> wrote:
>>>
>>>> On 05/09/2010 02:16, Jonathan M Davis wrote:
>>>>> void foo(T)(T[] collection, T elem)
>>>>>> {
>>>>>> // Blah, whatever
>>>>>> }
>>>>>>
>>>>
>>>> I am curious, how this will look and feel once inout is working ?
>>>>
>>>> inout void foo(T)(inout(T)[] collection, inout T elem)
>>>> {
>>>> // Blah, whatever}
>>>> }
>>>>
>>>
>>> inout void doesn't make any sense. You can't have a const void or
>>> immutable void.
>>>
>>> Now, if foo is a member function, then inout applies to the "this"
>>> pointer, but even then, you need a return type other than void for inout
>>> to be used.
>>>
>>> -Steve
>>
>> inout is only used when you want to return the same constness
>> (mutable, const, immutable) as you passed in to the function. If you
>> don't want that, or don't want to return anything then const(T)[] is
>> what you want. It will accept mutable, const and immutable.
>
> Yes, exactly. This is why inout functions cannot return void.
>
> -Steve

Hmm.

class C {
     void foo(void delegate(inout(C)) f) inout {
         f(this);
     }
}

Am I missing something?


More information about the Digitalmars-d-learn mailing list