inout functions

Piotr Szturmaj bncrbme at jadamspam.pl
Thu Aug 23 16:18:42 PDT 2012


Timon Gehr wrote:
> On 08/24/2012 12:14 AM, Piotr Szturmaj wrote:
>> Hi,
>>
>> I found this code of std.range.iota's Result struct:
>>
>>          @property inout(Value) front() inout { assert(!empty); return
>> current; }
>>
>> What's the purpose of inout on parameterless functions?
>
> It is a method of a struct, therefore it is not parameterless, but has
> a hidden parameter. 'inout' qualifies the implicit 'this' reference.
> Inside the method body, typeof(this) is inout(Result).

Thank you. So, it's helpful because struct might be qualified somewhere 
as const or as immutable. Anyway in that particular case it's 
unnecessary because iota's Result must be mutable to call popFront().

     immutable iotaRange = iota(0, 5);

     pragma(msg, typeof(&iotaRange.front));
     pragma(msg, typeof(iotaRange.front));

     io.popFront();

yields:

     inout(int) delegate() inout @property
     immutable(int)
     main.d(61): Error: function 
std.range.iota!(int,int).iota.Result.popFront () is not callable using 
argument types () immutable



More information about the Digitalmars-d-learn mailing list