Does D have too many features?

Walter Bright newshound2 at digitalmars.com
Mon Apr 30 19:39:31 PDT 2012


On 4/28/2012 1:32 PM, Timon Gehr wrote:
> On 04/28/2012 10:02 PM, Walter Bright wrote:
>> On 4/28/2012 12:36 PM, Andrej Mitrovic wrote:
>>> Also there's mixin templates. What exactly is the difference between
>>> mixin templates and regular templates?
>>
>> A mixin template is instantiated in context of the instantiation point,
>> while a regular template is instantiated in the context of the template
>> definition point.
>>
>> This becomes relevant when looking up symbols that are not defined
>> within the template.
>
> The implementation seems to disagree:
>
> int x;
> template X(){ // not a mixin template
> void y(){x=2;}
> }
>
> class C{
> int x;
> mixin X; // picks up local 'x'

Makes it a mixin template.

> }
>
> void main(){
> auto c = new C;
> c.y();
> import std.stdio;
> writeln(x," ",c.x); // "0 2"
> }
>
> Or am I misunderstanding your statement?

The behavior is as I described.


More information about the Digitalmars-d mailing list