Check whether function/delegate uses any shared or global variables

Nikhil Jacob via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Dec 12 03:37:04 PST 2016


On Monday, 12 December 2016 at 11:15:28 UTC, Nicholas Wilson 
wrote:
> On Monday, 12 December 2016 at 11:02:21 UTC, Nikhil Jacob wrote:
>> Is there any way to check whether a function/delegate passed 
>> to a function uses any shared or global variables ?
>>
>> I could not find any in std.traits.
>
> there is the pure function attribute, how ever this still 
> allows you to use globals *if you pass them as parameters to 
> the function*.
>
> see https://dlang.org/spec/function.html#pure-functions

Make sense.. I have two follow up questions

1. What about delegates ?
2. If a function is not explicitly declared as pure but satisfies 
the conditions of a pure function then can i check whether the 
function is pure using functionAttributes in std.traits.




More information about the Digitalmars-d-learn mailing list