Why do "const inout" and "const inout shared" exist?

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 1 16:29:36 PDT 2017


On 02.07.2017 00:26, Stefan Koch wrote:
> On Saturday, 1 July 2017 at 22:16:12 UTC, Timon Gehr wrote:
>>
>> struct S{
>>     int x;
>>     ref inout(int) foo()inout{
>>         return x;
>>     }
>> }
>>
>> void main(){
>>     S s;
>>     s.foo()++; // ok!
>>     const(S) t = s;
>>     import std.stdio;
>>     writeln(t.foo());
>>     // t.foo()++; // error
>> }
> 
> Oh damn. I was not aware that it could behave non-constly.
> since when does it do that ?

Since the beginning. :)

The point of inout is in essence to allow writing an identity function 
that can operate on data of any mutability qualifier with support for 
virtual calls and without duplicating code in the binary.


More information about the Digitalmars-d mailing list