September 29, 2016
On Thursday, 29 September 2016 at 18:55:07 UTC, Andrei Alexandrescu wrote:
> On 09/29/2016 02:53 PM, Ilya Yaroshenko wrote:
>> `(Index...)` -> `(size_t[] Index...)` // this is about template
>> arguments, not runtime
>
> What is the drawback of taking Index... and constraining it with a template constraint (all must be integral)? We use that in a few places in Phobos. -- Andrei

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.
September 29, 2016
On Thursday, 29 September 2016 at 18:56:40 UTC, Ilya Yaroshenko wrote:
> No, it does not
> ---
> void foo(size_t[] I...)(I i)
> {
> 	
> }

Using phobos' allSatisfy or a similar template, this can become:

    enum isIndex(T) = is(T == size_t);
    void foo(I...)(I i) if(allSatisfy!(isIndex, I)){ ... }
September 29, 2016
On Thursday, 29 September 2016 at 19:03:00 UTC, pineapple wrote:
> On Thursday, 29 September 2016 at 18:56:40 UTC, Ilya Yaroshenko wrote:
>> No, it does not
>> ---
>> void foo(size_t[] I...)(I i)
>> {
>> 	
>> }
>
> Using phobos' allSatisfy or a similar template, this can become:
>
>     enum isIndex(T) = is(T == size_t);
>     void foo(I...)(I i) if(allSatisfy!(isIndex, I)){ ... }

would not work:
auto v = cube[1, 2, 3];
September 29, 2016
Here's one way to do it:
------
import core.stdc.stdio;

void foo(T)(T[] a ...)
{
    printf("%d %d %d\n", a[0], a[1], a[2]);
}

void main()
{
    foo(1, 2, 3);
}
-----
C:\cbx>foo
1 2 3
September 29, 2016
On Thursday, 29 September 2016 at 20:12:44 UTC, Walter Bright wrote:
> Here's one way to do it:
> ------
> import core.stdc.stdio;
>
> void foo(T)(T[] a ...)
> {
>     printf("%d %d %d\n", a[0], a[1], a[2]);
> }
>
> void main()
> {
>     foo(1, 2, 3);
> }
> -----
> C:\cbx>foo
> 1 2 3

a.length must be known at CT. 99%-100% foreach loops in ndslice package are CT.
September 29, 2016
Ilya Yaroshenko <ilyayaroshenko@gmail.com> wrote:
> On Thursday, 29 September 2016 at 18:55:07 UTC, Andrei Alexandrescu wrote:
>> On 09/29/2016 02:53 PM, Ilya Yaroshenko wrote:
>>> `(Index...)` -> `(size_t[] Index...)` // this is about template
>>> arguments, not runtime
>> 
>> What is the drawback of taking Index... and constraining it with a template constraint (all must be integral)? We use that in a few places in Phobos. -- Andrei
> 
> 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?

September 29, 2016
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:
>>> On 09/29/2016 02:53 PM, Ilya Yaroshenko wrote:
>>>> `(Index...)` -> `(size_t[] Index...)` // this is about template
>>>> arguments, not runtime
>>> 
>>> What is the drawback of taking Index... and constraining it with a template constraint (all must be integral)? We use that in a few places in Phobos. -- Andrei
>> 
>> 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
September 29, 2016
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 ...) { /* ... */ }
September 29, 2016
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
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 ...) { /* ... */ }

YES! Many Thanks! This is what i need!