Mixin template evaluated to string can convert to string mixin expression implicitly

Timon Gehr timon.gehr at gmx.ch
Fri Jun 24 14:55:14 PDT 2011


Kenji Hara wrote:
> 2011/6/25 Timon Gehr <timon.gehr at gmx.ch>:
>> String mixins themselves are 'a little bit ugly' (but unquestionably very
> useful).
>> I think the syntax should keep reflecting that.
>>
>> Your proposal is a try to make up for Ds lack of macros. I'd prefer macros.
>> Also overloading the meaning of 'mixin template' seems to be questionable. As I
>> understand it, your proposal would make code like this valid?:
>>
>> mixin template bar(bool b){
>>    static if(b){
>>        enum bar="foo(123);"
>>    }else{
>>        int foo(int x){
>>            return 123+x;
>>        }
>>    }
>> }
>>
>> int main(){
>>    mixin bar!(0);
>>    int x=bar!(1);
>>    assert(x == 246);
>> }
>>
>> This does not seem quite right to me.
>>
>> Cheers,
>> -Timon
>
> Yes, you can write template like that.
> But it seems to me that is not good even if implicit string mixin is not used.
>
> Kenji

What I wanted to point out with the example was that your proposal overloads
'mixin template' with two completely orthogonal functionalities:

- Prevent instantiation as a normal template/At instantiation point, require
explicit 'mixin'.
- Allow instantiation as a normal template. At instantiation point, 'mixin(.)' is
added implicitly.


Timon


More information about the Digitalmars-d mailing list