Type programming game
claptrap
clap at trap.com
Mon Oct 12 14:04:56 UTC 2020
On Sunday, 11 October 2020 at 10:46:00 UTC, Stefan Koch wrote:
> On Sunday, 11 October 2020 at 09:31:43 UTC, Basile B. wrote:
>> On Saturday, 10 October 2020 at 23:42:46 UTC, Stefan Koch
>> wrote:
>>> Hi,
>>>
> static assert(double_triple(int,int,uint,uint,uint) == "double
> int triple uint");
> static assert(double_triple(char,char,wchar,dchar,dchar) ==
> "double char double dchar");
> static assert(double_triple(double, double, float, float,
> float) == "double double triple float");
> ---
>
> In continuation I will post benchmarks of all 4 (or more of
> others come in) solutions on longer type sequences.
Maybe this type function version will work
string double_triple(type[] types...)
{
string result;
uint subidx = 0;
foreach(i, t; types)
{
if ((i == types.length-1) || is(types[i] != types[i+1]))
{
result ~= ["","double","triple","quadruple"][i-subidx]
~ __traits(identifier, t) ~ " ";
subidx = i+1;
}
}
return result;
}
More information about the Digitalmars-d
mailing list