It turns out it's quite hard to have @safe pure nothrow functions. Oh, and const.

Jakob Ovrum via Digitalmars-d digitalmars-d at puremagic.com
Sat Sep 13 18:38:31 PDT 2014


On Saturday, 13 September 2014 at 19:58:16 UTC, Kagamin wrote:
> On Saturday, 13 September 2014 at 18:36:53 UTC, Timon Gehr 
> wrote:
>> On 09/13/2014 07:48 PM, Kagamin wrote:
>>> On Saturday, 13 September 2014 at 16:51:09 UTC, Timon Gehr 
>>> wrote:
>>>> s.bar((int* p){ ++*p; });
>>>
>>> Huh? inout is for functions, which don't modify their 
>>> arguments.
>>
>> With Jakob's code working, this would not be warranted.
>
> Huh? See rationale in 
> https://issues.dlang.org/show_bug.cgi?id=1961

The function doesn't modify `p` - it's modified by a callback 
that was accepted because it's known at the call-site that `p` is 
modifiable.

This is necessary for `inout` to work with callback functions, 
such as with internal iteration (i.e. `opApply`). It can be 
worked around exactly the same way you would work around it with 
functions that return a value - by duplicating the function. It 
is essentially the same problem and thus `inout` could easily be 
used to fix it.


More information about the Digitalmars-d mailing list