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

Lodovico Giaretta via Digitalmars-d digitalmars-d at puremagic.com
Wed Jul 6 01:05:38 PDT 2016


On Wednesday, 6 July 2016 at 07:47:18 UTC, Tofu Ninja wrote:
> I think there needs to be some kind of opt-in attribute to 
> indicate that the template should use the instantiating 
> module's access rights. There are three things it would need to 
> do...
>
> 1) It would need to cause the template instantiation to have 
> the same access rights as the instantiating module.
>
> 2) It would need to tie the instantiation to the instantiating 
> module, different module will have different access rights so 
> the templates won't match.
>
> 3) It would need to transmit these access rights through other 
> templates if they also have the opt-in attribute. All the 
> templates would have the instantiating scopes access rights. It 
> would be needed in cases like allocator.make which ends up 
> calling emplace eventually. The access rights would need to be 
> transmitted all the way to emplace.
>
> The attribute could be argument specific or applied to the 
> whole template, I am not sure which would be better but they 
> could both work.

Thinking about this, maybe the choice about attributes should be 
made by the user, so that if I want to give emplace access to 
private ctors of my structs, I have to explicitly declare inside 
my module that I'm going to give emplace those rights (which in 
turn are propagated to whatever templates emplace uses 
internally).
This way the template writer doesn't have to bother whether his 
template needs those rights, it is clear which templates have 
them without looking at their declarations, and users can decide 
not to grant these rights (bonus point: this way nothing changes 
behaviour unless the user wants so).


More information about the Digitalmars-d mailing list