mixin template and overloading
anonymous via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jan 20 05:07:35 PST 2015
On Tuesday, 20 January 2015 at 11:30:39 UTC, Luc Bourhis wrote:
> Consider:
>
> ~ % dmd -v|head -n 1
> DMD64 D Compiler v2.066-devel
>
> ~% cat mixin_template_pb.d
> mixin template Foo(T) {
> void bar() {}
> }
>
> struct FooBar {
> mixin Foo!int;
> void bar(ulong d)() {}
> }
>
> void check() {
> FooBar o;
> o.bar();
> }
> ~% dmd -c mixin_template_pb.d
> mixin_template_pb.d(12): Error: template
> mixin_template_pb.FooBar.bar cannot deduce function from
> argument types !()(), candidates are:
> mixin_template_pb.d(7):
> mixin_template_pb.FooBar.bar(ulong d)()
>
> It looks like the compiler does not see the mixed-in "bar". If
> I comment out the definition of "bar" in "FooBar", it compiles
> fine. Is this to be considered a bug?
No, it's working as intended: "If the name of a declaration in a
mixin is the same as a declaration in the surrounding scope, the
surrounding declaration overrides the mixin one" --
http://dlang.org/template-mixin.html
You can use `alias` to bring the two together:
struct FooBar {
mixin Foo!int f;
alias bar = f.bar;
void bar(ulong d)() {}
}
More information about the Digitalmars-d
mailing list