Pure delegate not quite pure?
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jun 30 15:06:03 PDT 2015
On 6/30/15 5:44 PM, Tofu Ninja wrote:
> On Tuesday, 30 June 2015 at 21:31:05 UTC, Steven Schveighoffer wrote:
>> On 6/30/15 5:23 PM, Tofu Ninja wrote:
>>> On Sunday, 28 June 2015 at 10:19:05 UTC, anonymous wrote:
>>>> [...]
>>>
>>> Is there any way to annotate the context as const?
>>
>> const x = 4 ;)
>>
>> But even if you could annotate just the *reference* as const, it
>> doesn't stop foo from changing it as you did in the example.
>>
>
> Yeah, but I am more worried about d changing x by itself(though foo
> changing it is still a problem), I have a piece of code that takes a
> delegate and I want to ensure that it runs in the same way every time
> once it's given to me.
Have you tried placing const on the function signature? i.e.:
pure int delegate() const d = () const {...
That's how you'd do it (I think, didn't test) if the delegate context
pointer was a class/struct.
-Steve
More information about the Digitalmars-d-learn
mailing list