public alias to private template implementation

monarch_dodra monarchdodra at gmail.com
Mon Sep 16 14:00:20 PDT 2013


Reduced:

//----
module A;

alias fun = Impl!int;

private template Impl(T)
{
     void Impl(){}
}
//----
void main()
{
     fun();
}
//----
Error: function A.Impl!int.Impl is not accessible from module main
//----

I'm trying to implement a set of public funtions, in terms of a 
template. Said template has no business being know to the user, 
so I want to mark it as private. Unfortunately, if I do this, 
then I can't use the alias, because "Impl is private".

Question 1: Is this the correct behavior? I'd have expected that 
if my alias is public, it would allow any one from outside to 
make the call correctly.

Question 2: Is there a "correct" way to do this? I possible, I'd 
want to avoid "nesting" the template, eg:
auto fun(){return Impl!int();}
As that would:
a) require more typing ^^
b) incur an extra function call in non-inline
c) if at all possible, I actually need "fun" to be a template, so 
that it can be inlined.


More information about the Digitalmars-d-learn mailing list