public alias to private template implementation

monarch_dodra monarchdodra at gmail.com
Tue Sep 17 02:30:09 PDT 2013


On Tuesday, 17 September 2013 at 08:47:25 UTC, Joseph Rushton 
Wakeling wrote:
> On 16/09/13 23:00, monarch_dodra wrote:
>> 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.
>
> See: http://d.puremagic.com/issues/show_bug.cgi?id=10996
>
>> 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.
>
> Indeed, I used that workaround of manually nesting the 
> functions in some code of mine:
> https://github.com/WebDrake/Dgraph/blob/master/dgraph/graph.d#L492-L516
>
> ... but that's not a general solution, I was able to tolerate 
> it because it's a limited and predictable set of instructions.
>
> Jacob Carlborg suggested using opDispatch (cf. how it's done in 
> Proxy), which should automate the "nesting" of template 
> functions.  I avoided it simply because in my case I thought 
> that doing it manually would be less hassle than getting 
> opDispatch set up to cover every possible case, but depending 
> on your use case it might be the better option.

Thanks. I'm not very fluent with opDispatch though. Doesn't that 
only work if you have an struct/class instance though? My "fun" 
is a free frunction.

I you are able to adapt it to my trivial usecase, it might be 
clearer to me what you have in mind.


More information about the Digitalmars-d-learn mailing list