September 29, 2016 Re: DIP Mir1 Draft: Variadic template parameters with the same time. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Yaroshenko Attachments:
| this works: void foo(T, size_t n)(T[n] a ...) {...} However, see this: https://github.com/libmir/mir/issues/337 On Thu, Sep 29, 2016 at 1:57 PM, Ilya Yaroshenko via Digitalmars-d < digitalmars-d@puremagic.com> wrote: > On Thursday, 29 September 2016 at 20:54:12 UTC, Ilya Yaroshenko wrote: > >> On Thursday, 29 September 2016 at 20:47:35 UTC, Andrei Alexandrescu wrote: >> >>> Ilya Yaroshenko <ilyayaroshenko@gmail.com> wrote: >>> >>>> On Thursday, 29 September 2016 at 18:55:07 UTC, Andrei Alexandrescu wrote: >>>> >>>>> [...] >>>>> >>>> >>>> This is the same like in current ndslice code. >>>> For 3D cube[i, j, k] 64(!) templates can be generated because >>>> each of i, j, k can be int, uint, size_t, sizediff_t. >>>> >>>> >>> Yah, I remember. Can you experiment with arranging things such that all templates forward to the same backend function that does the work? >>> >> >> This already done. But anyway lot of template bloat would note disappeared. In addition there are inlining and mapSlice >> > > I am sorry for my terrible English (i am in a dark room now) > |
September 29, 2016 Re: DIP Mir1 Draft: Variadic template parameters with the same time. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timothee Cour | On Thursday, 29 September 2016 at 21:06:13 UTC, Timothee Cour wrote: > this works: > > void foo(T, size_t n)(T[n] a ...) {...} > > However, see this: https://github.com/libmir/mir/issues/337 > > > On Thu, Sep 29, 2016 at 1:57 PM, Ilya Yaroshenko via Digitalmars-d < digitalmars-d@puremagic.com> wrote: > >> On Thursday, 29 September 2016 at 20:54:12 UTC, Ilya Yaroshenko wrote: >> >>> On Thursday, 29 September 2016 at 20:47:35 UTC, Andrei Alexandrescu wrote: >>> >>>> Ilya Yaroshenko <ilyayaroshenko@gmail.com> wrote: >>>> >>>>>[...] >>>> Yah, I remember. Can you experiment with arranging things such that all templates forward to the same backend function that does the work? >>>> >>> >>> This already done. But anyway lot of template bloat would note disappeared. In addition there are inlining and mapSlice >>> >> >> I am sorry for my terrible English (i am in a dark room now) Thanks! ag0aep6g have suggested the same. I am confused that I did know this solution. Will open separate thread for https://github.com/libmir/mir/issues/337. |
September 29, 2016 Re: DIP Mir1 Draft: Variadic template parameters with the same time. | ||||
---|---|---|---|---|
| ||||
Posted in reply to ag0aep6g | On Thursday, 29 September 2016 at 20:57:00 UTC, ag0aep6g wrote:
> On 09/29/2016 10:43 PM, Ilya Yaroshenko wrote:
>> On Thursday, 29 September 2016 at 20:12:44 UTC, Walter Bright wrote:
> [...]
>>> void foo(T)(T[] a ...)
>>> {
>>> printf("%d %d %d\n", a[0], a[1], a[2]);
>>> }
> [...]
>>
>> a.length must be known at CT. 99%-100% foreach loops in ndslice package
>> are CT.
>
> I'm not sure if I understand the goal, but what about this:
>
> void foo(size_t n)(size_t[n] a ...) { /* ... */ }
Just found an example, where this approach does not work :-(
template transposed(Dimensions...)
if (Dimensions.length)
{
Slice!(N, Range) transposed(size_t N, Range)(auto ref Slice!(N, Range) slice)
{
...
}
}
|
September 29, 2016 Re: DIP Mir1 Draft: Variadic template parameters with the same time. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Yaroshenko Attachments:
| maybe remove the corresponding DIP from https://github.com/libmir/mir/wiki/Compiler-and-druntime-bugs#dips ? On Thu, Sep 29, 2016 at 2:19 PM, Ilya Yaroshenko via Digitalmars-d < digitalmars-d@puremagic.com> wrote: > On Thursday, 29 September 2016 at 21:06:13 UTC, Timothee Cour wrote: > >> this works: >> >> void foo(T, size_t n)(T[n] a ...) {...} >> >> However, see this: https://github.com/libmir/mir/issues/337 >> >> >> On Thu, Sep 29, 2016 at 1:57 PM, Ilya Yaroshenko via Digitalmars-d < digitalmars-d@puremagic.com> wrote: >> >> On Thursday, 29 September 2016 at 20:54:12 UTC, Ilya Yaroshenko wrote: >>> >>> On Thursday, 29 September 2016 at 20:47:35 UTC, Andrei Alexandrescu >>>> wrote: >>>> >>>> Ilya Yaroshenko <ilyayaroshenko@gmail.com> wrote: >>>>> >>>>> [...] >>>>>> >>>>> Yah, I remember. Can you experiment with arranging things such that all templates forward to the same backend function that does the work? >>>>> >>>>> >>>> This already done. But anyway lot of template bloat would note disappeared. In addition there are inlining and mapSlice >>>> >>>> >>> I am sorry for my terrible English (i am in a dark room now) >>> >> > Thanks! ag0aep6g have suggested the same. I am confused that I did know this solution. Will open separate thread for https://github.com/libmir/mir/issues/337. > |
September 29, 2016 Re: DIP Mir1 Draft: Variadic template parameters with the same time. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timothee Cour | On Thursday, 29 September 2016 at 21:31:11 UTC, Timothee Cour wrote:
> maybe remove the corresponding DIP from https://github.com/libmir/mir/wiki/Compiler-and-druntime-bugs#dips ?
>
> On Thu, Sep 29, 2016 at 2:19 PM, Ilya Yaroshenko via Digitalmars-d < digitalmars-d@puremagic.com> wrote:
>
>> On Thursday, 29 September 2016 at 21:06:13 UTC, Timothee Cour wrote:
>>
>>> this works:
>>>
>>> void foo(T, size_t n)(T[n] a ...) {...}
>>>
>>> However, see this: https://github.com/libmir/mir/issues/337
>>>
>>>
>>> On Thu, Sep 29, 2016 at 1:57 PM, Ilya Yaroshenko via Digitalmars-d < digitalmars-d@puremagic.com> wrote:
>>>
>>> On Thursday, 29 September 2016 at 20:54:12 UTC, Ilya Yaroshenko wrote:
>>>>
>>>> On Thursday, 29 September 2016 at 20:47:35 UTC, Andrei Alexandrescu
>>>>>[...]
>>>> I am sorry for my terrible English (i am in a dark room now)
>>>>
>>>
>> Thanks! ag0aep6g have suggested the same. I am confused that I did know this solution. Will open separate thread for https://github.com/libmir/mir/issues/337.
Just found an example, where this approach does not work :-(
template transposed(Dimensions...)
if (Dimensions.length)
{
Slice!(N, Range) transposed(size_t N, Range)(auto ref Slice!(N, Range) slice)
{
...
}
}
|
September 30, 2016 Re: DIP Mir1 Draft: Variadic template parameters with the same time. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Yaroshenko | On 09/29/2016 11:28 PM, Ilya Yaroshenko wrote: > On Thursday, 29 September 2016 at 20:57:00 UTC, ag0aep6g wrote: [...] >> void foo(size_t n)(size_t[n] a ...) { /* ... */ } > > Just found an example, where this approach does not work :-( > > template transposed(Dimensions...) > if (Dimensions.length) > { > Slice!(N, Range) transposed(size_t N, Range)(auto ref Slice!(N, > Range) slice) > { > ... > } > } When the values themselves are known at compile time, we can convert them to size_t before generating the function: ---- enum isIndex(T) = is(T == size_t); /* by pineapple */ enum asIndex(size_t value) = value; template transposed(Dimensions...) if (Dimensions.length) { import std.meta: allSatisfy, staticMap; static if (allSatisfy!(isIndex, typeof(Dimensions))) { void transposed() {} /* simplified for the example */ } else { alias transposed = transposed!(staticMap!(asIndex, Dimensions)); } } alias t1 = transposed!(1, 2, 3); alias t2 = transposed!(1LU, 2LU, 3LU); static assert(&t1 == &t2); /* passes */ ---- |
September 29, 2016 Re: DIP Mir1 Draft: Variadic template parameters with the same time. | ||||
---|---|---|---|---|
| ||||
Posted in reply to ag0aep6g | On Thursday, 29 September 2016 at 22:03:36 UTC, ag0aep6g wrote:
> On 09/29/2016 11:28 PM, Ilya Yaroshenko wrote:
>> [...]
> [...]
>> [...]
>
> When the values themselves are known at compile time, we can convert them to size_t before generating the function:
>
> ----
> enum isIndex(T) = is(T == size_t); /* by pineapple */
> enum asIndex(size_t value) = value;
>
> template transposed(Dimensions...)
> if (Dimensions.length)
> {
> import std.meta: allSatisfy, staticMap;
> static if (allSatisfy!(isIndex, typeof(Dimensions)))
> {
> void transposed() {} /* simplified for the example */
> }
> else
> {
> alias transposed = transposed!(staticMap!(asIndex, Dimensions));
> }
> }
>
> alias t1 = transposed!(1, 2, 3);
> alias t2 = transposed!(1LU, 2LU, 3LU);
>
> static assert(&t1 == &t2); /* passes */
> ----
Thanks again!
|
Copyright © 1999-2021 by the D Language Foundation