Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- import std.traits;
- class Foo {
- void go(T)(T t) { writefln("Foo.go(T)"); }
- void go(T : int)(T t) { writefln("Foo.go(T : int)"); }
- }
- // Declares just a specialization of go(T) given a type
- mixin template MakeGo(U) {
- mixin("void go(T : " ~ fullyQualifiedName!(U) ~ ")(T t) {" ~
- "writefln(\"MakeGo.go(T : U)\"); }");
- }
- // Declares both go(T) and a specialization of go(T) given a type
- mixin template MakeGo2(U) {
- mixin("void go(T)(T t) { writefln(\"MakeGo2.go(T)\"); }\n" ~
- "void go(T : " ~ fullyQualifiedName!(U) ~ ")(T t) { writefln(\"MakeGo2.go(T : U)\"); }");
- }
- class Bar {
- void go(T)(T t) { writefln("Bar.go(T)"); }
- mixin("void go(T : int)(T t) { writefln(\"Bar.go(T : int)\"); }");
- mixin MakeGo!(Foo);
- }
- class Baz {
- mixin MakeGo2!(Foo);
- }
- void main() {
- auto foo = new Foo();
- foo.go("foo");
- foo.go(0);
- auto bar = new Bar();
- bar.go("bar");
- bar.go(0);
- // XXX: This should call MakeGo.go(T : U), but it calls Bar.go(T) instead.
- bar.go(foo);
- auto baz = new Baz();
- // This correctly calls MakeGo2.go(T)
- baz.go("baz");
- // And this correctly calls MakeGo2.go(T : U)
- baz.go(foo);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement