d - How do I specialize templates across different modules? -
module a; void foo(t)(){ import std.stdio; writeln(t.stringof); } module b; import a; private alias foo = a.foo; void foo(t: int)(){ import std.stdio; writeln("special int"); } //app.d void main() { import a; import b; foo!int(); }
this prints int
instead of special int
. possible specialize templates across different modules?
can assume answer d template specialization in different source file still relevant today?
your alias wrong , import introduces ambiguities. if want publicly overloadable, don't make alias private!
once alias made public (the default btw), compiling spit out name conflict error:
iii.d(6): error: a.foo(t)() @ ii.d(2) conflicts b.foo @ i.d
then, simple matter of disambiguating (specifying b.foo!int()
), or better yet, removing unnecessary import a
usage point.
//app.d void main() { import b; foo!int(); }
special int!
for more complex cases, can make wrapper template , forward arguments, here simple alias overloading - when done alias foo = a.foo;
, no private
, trick.
Comments
Post a Comment