Doc Comments /
Mixin
Template Mixins
Messages
Add your comments here...
Scope
The original documentation states ...If two different mixins are put in the same scope, and each define a declaration with the same name, there is an ambiguity error when the declaration is referenced:
However, to clear up a slight documentation ambiguity, it might better read ...
If two or more mixins statements are put in the same scope, and any two define a declaration with the same name, there is an ambiguity error when the declaration is referenced:
The difference is that the original statement could give the impression that it is talking about different template names rather than different instances of a mixin statement. This impression is further suggested by the example that is given.
Example: Disambiguating declarations with the same name
To disambiguate declarations with the same name, introduced by different mixin statements, you must use a mixinidentifier with or without an alias.import std.stdio; template Foo(T) { void Bar(T a) { writefln("Bar ", a); } } mixin Foo!(int) I; alias I.Bar Bar; mixin Foo!(real) R; alias R.Bar Bar; void main() { Bar(1); // invokes I.Bar because an int was supplied. Bar(5.1); // invokes R.Bar because a real was supplied. }
Links
- Corresponding page in the D Specification
- Mixins vs. Macros
- Newsgroup threads