Should templates have the instantiating scope's protection access rights?

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 5 11:04:31 PDT 2016


On 7/5/16 1:46 PM, Tofu Ninja wrote:
> Sorry if this has been posted before.
>

Pretty recently actually: 
https://forum.dlang.org/post/rduvpfuzfzmzhoknsrkr@forum.dlang.org

> One possible solution could be that templates have the access rights of
> the instantiating scope. This is honestly what I expect most of the time
> but there are probably cases where this would muck things up. Maybe a
> more case by case solution would be better.

The clear problem with this solution is that this means you must use the 
instantiating module as part of the template definition. A template 
instantiation with exactly the same parameters must behave exactly the 
same, no matter where it was instantiated from.

What this means, is that each instantiation is now tied to the module 
instantiating it, with no code reuse. I think at the very least, this 
should be opt-in if it even makes sense to do.

-Steve



More information about the Digitalmars-d mailing list