digitalmars.D.learn - inout functions
- Piotr Szturmaj (5/5) Aug 23 2012 Hi,
- Timon Gehr (4/9) Aug 23 2012 It is a method of a struct, therefore it is not parameterless, but has
- Piotr Szturmaj (14/26) Aug 23 2012 Thank you. So, it's helpful because struct might be qualified somewhere
- Kagamin (2/2) Aug 24 2012 Well, it may be also a way to ensure the function doesn't modify
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?
Aug 23 2012
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).
Aug 23 2012
Timon Gehr wrote:On 08/24/2012 12:14 AM, Piotr Szturmaj wrote: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 () immutableHi, 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).
Aug 23 2012
Well, it may be also a way to ensure the function doesn't modify the struct.
Aug 24 2012