Can't pass private symbols as alias parameter
deadalnix via Digitalmars-d
digitalmars-d at puremagic.com
Mon Nov 17 14:11:19 PST 2014
On Monday, 17 November 2014 at 14:13:21 UTC, Steven Schveighoffer
wrote:
> I note here, the above doesn't is incorrect regardless, I
> assume you didn't actually try to compile this post example :)
>
> To fix, I did this:
>
> struct A(alias foo) {
> auto bar() {
> return foo();
> }
> }
>
Sorry for that, I made a mistake while typing the sample code.
> The alias cannot override the protection attributes, and I'm
> pretty sure that is intentional.
>
> I tried some workarounds:
>
> void main() {
> public alias b = bar;
> auto a = A!b();
> }
>
> It would be nice if that worked, because it does not expose bar
> except in this one case, and it identifies that you know bar
> has become public for this one case. But unfortunately, it has
> the same issue.
>
:'(
> This works:
>
> void main() {
> static auto b() { return bar();}
> auto a = A!b();
> }
>
> But of course, it's not ideal, as you are relying on the
> inliner to make this performant. Shortened version (I think
> this implies static):
>
> auto a = A!(()=>bar())();
>
> Yuck. I really think what you wish should be allowed, even if
> using some syntax to declare you know what you are doing.
>
> I tried some other goofy stuff, but I could not get around the
> requirement that the alias not change the protection of the
> symbol.
>
> -Steve
This is not an option to me. In my specific use case, the code
instantiating the template is itself a template, and they call
each other. That mean I get infinite template instantiation.
More information about the Digitalmars-d
mailing list