Does D have too many features?

Artur Skawina art.08.09 at gmail.com
Sun Apr 29 18:27:46 PDT 2012


On 04/30/12 02:33, Simen Kjaeraas wrote:
> On Sat, 28 Apr 2012 22:40:10 +0200, Artur Skawina <art.08.09 at gmail.com> wrote:
> 
>> On 04/28/12 22:02, 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.
>>
>> Yeah, but this was actually the only suggestion so far in this thread that
>> i could agree with... The issue is
>>
>>    template t1() { int a = b; }
>>    int main() { int b; mixin t1; return a; }
>>
>> which is currently accepted - and would enforcing the mixin annotation
>> really help anything?
>>
>> artur
> 
> At least some of us want mixin templates to be marked mixin at declaration
> point, and usable without 'mixin':
> 
> mixin template A( ) {
>     int n;
> }
> 
> struct S {
>     A!();
> }

Yes, that's the other possible use for marking a template as a mixin. Unlike
my above example it wouldn't then be redundant; the question is however if
this functionality really is desirable...

   mixin template t1() { auto _ = a = b; }
   int main() { int a, b=1; t1!(); return a; }

This program would now return '1', which can be non-obvious if you don't
know the definition of 't1'. Right now you have to write that as

   template t1() { auto _ = a = b; }
   int main() { int a, b=1; mixin t1!(); return a; }

so the mixin is clearly visible.

These kind of template macros would be useful and i'd like to have them too,
but there is a cost, and i'm not yet sure that being able to omit the 'mixin'
keyword would be worth it.

artur


More information about the Digitalmars-d mailing list