Type programming game

claptrap clap at trap.com
Wed Oct 14 00:11:37 UTC 2020


On Tuesday, 13 October 2020 at 14:43:23 UTC, Stefan Koch wrote:
> On Monday, 12 October 2020 at 14:04:56 UTC, claptrap wrote:
> I fixed your version to work around the bugs in type functions.
> (As of git commit 1652c194870f9c66161888425a9cdf01db8187f6 (in 
> https://github.com/UplinkCoder/dmd/tree/talias_master))
>
> Here is it fixed:
> ---
>
> alias type = __type;
> string double_triple(type[] types...)
> {
>     string result;
>     size_t subidx = 0;
>
>     foreach(i, t; types)
>     {
>         // for some reason using type[idx] will only work 
> within an assign exp
>         // this still to be fixed
>         auto t2 = (i == types.length-1) ? cast(type)type.init : 
> types[i+1];
>         if (!is(t2 == t)) // this works because if t2 is 
> type.init it will eval to false;
>         {
>             if (i-subidx)
>             {
>                 result ~= 
> ["","double","triple","quadruple"][i-subidx]
>                     ~ " " ~ __traits(identifier, t) ~ " ";
>             }
>
>            subidx = i+1;
>         }
>     }
>     return result[0 .. $-1];
> }
>
> static assert(double_triple(char,char,wchar,dchar,dchar) == 
> "double char double dchar");
> static assert(double_triple(char,char,wchar,dchar,dchar, dchar) 
> == "double char triple dchar");
> ---

Yeah not as concise as it could be, but I assume eventually 
type[idx] will work outside assign expressions?




More information about the Digitalmars-d mailing list