Template visibility

David Nadlinger via Digitalmars-d digitalmars-d at puremagic.com
Wed Aug 31 06:51:03 PDT 2016


On Wednesday, 31 August 2016 at 12:45:14 UTC, Ethan Watson wrote:
> But in this case, because instantiation happens within the 
> scope of the binderoo.typedescriptor module instead of within 
> the scope of the module the template is invoking from, it just 
> can't see my new CTypeNameOverride specialisation.

This analysis is correct, and no, there is no direct way of 
emulating argument-dependent lookup (or the existence of a single 
global scope, for that matter) in D. You have to funnel in the 
information via the template parameter somehow, as you did with 
UDAs.

An alternative solution might be to make the your binderoo 
library use an explicit context, where such overrides can be 
registered manually at the point where both it and the vector 
library in question are in use (i.e. the client library/program). 
One option for this would be explicit context arguments, another 
to wrap the API into one giant template which injects that extra 
information (`alias myBinderoo = binderoo!(overrides, ...); 
myBinderoo.doSomething!foo(bar);`).

  — David


More information about the Digitalmars-d mailing list