October 13
On Monday, 12 October 2020 at 14:04:56 UTC, claptrap wrote:
> 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;
> }

Thanks for you submission.
You helped me to find a bug within the TF implementation.

For some reason indexing of types[] that does not happen automatically in the foreach doesn't work.
(Which is really strange because under the hood it should use the same code...)

There is one mistake in your code which I would like to correct.
is-expressions cannot use !=
you have to state it as:
> (!is(types[i] ==  types[i+1]))

Other than that the code should run well, as soon as the bug with the indexing of __type arrays is fixed.
October 13
On Monday, 12 October 2020 at 14:04:56 UTC, claptrap wrote:
>
> 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;
> }

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");
---

October 14
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?


October 14
On Wednesday, 14 October 2020 at 00:11:37 UTC, claptrap wrote:
> 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.
>> [...]
> Yeah not as concise as it could be, but I assume eventually type[idx] will work outside assign expressions?

Yes of course.
4 days ago
On Wednesday, 14 October 2020 at 11:14:34 UTC, Stefan Koch wrote:
> On Wednesday, 14 October 2020 at 00:11:37 UTC, claptrap wrote:
>> 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.
>>> [...]
>> Yeah not as concise as it could be, but I assume eventually type[idx] will work outside assign expressions?
>
> Yes of course.

So what's up with the benchmark you mentioned ? With four entries + your TF version we can have a podium now.
4 days ago
On Saturday, 17 October 2020 at 12:46:44 UTC, Basile B. wrote:
> On Wednesday, 14 October 2020 at 11:14:34 UTC, Stefan Koch wrote:
>> On Wednesday, 14 October 2020 at 00:11:37 UTC, claptrap wrote:
>>> 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.
>>>> [...]
>>> Yeah not as concise as it could be, but I assume eventually type[idx] will work outside assign expressions?
>>
>> Yes of course.
>
> So what's up with the benchmark you mentioned ? With four entries + your TF version we can have a podium now.

Coming up. Fixes to accommodate claptrap's original version have to be made first.
4 days ago
On Saturday, 17 October 2020 at 12:53:44 UTC, Stefan Koch wrote:
> On Saturday, 17 October 2020 at 12:46:44 UTC, Basile B. wrote:
>> On Wednesday, 14 October 2020 at 11:14:34 UTC, Stefan Koch wrote:
>>> On Wednesday, 14 October 2020 at 00:11:37 UTC, claptrap wrote:
>>>> 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.
>>>>> [...]
>>>> Yeah not as concise as it could be, but I assume eventually type[idx] will work outside assign expressions?
>>>
>>> Yes of course.
>>
>> So what's up with the benchmark you mentioned ? With four entries + your TF version we can have a podium now.
>
> Coming up. Fixes to accommodate claptrap's original version have to be made first.

yeah but his version is a TF one BTW. Maybe I missed the point, weren't we supposed to propose a version based on CTFE+template only ?
4 days ago
On Saturday, 17 October 2020 at 12:59:19 UTC, Basile B. wrote:
> On Saturday, 17 October 2020 at 12:53:44 UTC, Stefan Koch wrote:
>> On Saturday, 17 October 2020 at 12:46:44 UTC, Basile B. wrote:
>>> On Wednesday, 14 October 2020 at 11:14:34 UTC, Stefan Koch wrote:
>>>> On Wednesday, 14 October 2020 at 00:11:37 UTC, claptrap wrote:
>>>>> [...]
>>>>
>>>> Yes of course.
>>>
>>> So what's up with the benchmark you mentioned ? With four entries + your TF version we can have a podium now.
>>
>> Coming up. Fixes to accommodate claptrap's original version have to be made first.
>
> yeah but his version is a TF one BTW. Maybe I missed the point, weren't we supposed to propose a version based on CTFE+template only ?

You can propose a version using anything that you think will work.
As long as I can get a version of DMD that can compile it.
4 days ago
On Saturday, 17 October 2020 at 13:37:20 UTC, Stefan Koch wrote:
> On Saturday, 17 October 2020 at 12:59:19 UTC, Basile B. wrote:
>> On Saturday, 17 October 2020 at 12:53:44 UTC, Stefan Koch wrote:
>>> On Saturday, 17 October 2020 at 12:46:44 UTC, Basile B. wrote:
>>>> On Wednesday, 14 October 2020 at 11:14:34 UTC, Stefan Koch wrote:
>>>>> On Wednesday, 14 October 2020 at 00:11:37 UTC, claptrap wrote:
>>>>>> [...]
>>>>>
>>>>> Yes of course.
>>>>
>>>> So what's up with the benchmark you mentioned ? With four entries + your TF version we can have a podium now.
>>>
>>> Coming up. Fixes to accommodate claptrap's original version have to be made first.
>>
>> yeah but his version is a TF one BTW. Maybe I missed the point, weren't we supposed to propose a version based on CTFE+template only ?
>
> You can propose a version using anything that you think will work.
> As long as I can get a version of DMD that can compile it.

Actually, and even it's sure that TF version will be faster, I could propose a second version of my entry since the bounds of the dynamic array I use are tied to the length of the variadic template arg... So I can use static arrays and a variable to give the upper bound in the array of unique types.

Not sure if it is worth ;)
Next ›   Last »
1 2