Mixin template function

Jacob Carlborg doob at me.com
Wed Feb 13 23:40:57 PST 2013


On 2013-02-14 01:29, cal wrote:
> Should the following work?
>
> import std.traits;
>
> mixin template Foo()
> {
>      void foo(T)(T t) if (isSomeString!T) {}
> }
>
> class A
> {
>      void foo()(int i){}
>      mixin Foo;
> }
>
> void main()
> {
>      auto a = new A;
>      a.foo("hello");
> }
>
> Error: template hello.A.foo does not match any function template
> declaration. Candidates are:
> hello.A.foo()(int i)
>
> If i give the mixin an identifier (mixin Foo _foo) and call it like
> a._foo.foo("hello") then it works. I thought it should work without that
> though.

This is by design. Foo and A have different overload sets. Try:

alias Foo.foo foo;

http://dlang.org/template-mixin.html

Search for: "Mixin Scope" and pay attention to:

"Alias declarations can be used to overload together functions declared 
in different mixins".

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list