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

kenji hara k.hara.pg at gmail.com
Fri Jun 24 09:30:35 PDT 2011


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


More information about the Digitalmars-d mailing list