Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Ilya Yaroshenko via Digitalmars-d
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); /*

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread ag0aep6g via Digitalmars-d
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) {

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Ilya Yaroshenko via Digitalmars-d
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

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Timothee Cour via Digitalmars-d
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

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Ilya Yaroshenko via Digitalmars-d
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

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Ilya Yaroshenko via Digitalmars-d
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

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Timothee Cour via Digitalmars-d
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: >

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Ilya Yaroshenko via Digitalmars-d
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 wrote: On Thursday, 29 September 2016 at 18:55:07 UTC, Andrei Alexandrescu wrote: [...] This is the

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread ag0aep6g via Digitalmars-d
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

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Ilya Yaroshenko via Digitalmars-d
On Thursday, 29 September 2016 at 20:47:35 UTC, Andrei Alexandrescu wrote: Ilya Yaroshenko 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

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Andrei Alexandrescu via Digitalmars-d
Ilya Yaroshenko 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

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Ilya Yaroshenko via Digitalmars-d
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%

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Walter Bright via Digitalmars-d
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

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread pineapple via Digitalmars-d
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)){ ...

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Ilya Yaroshenko via Digitalmars-d
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 ==

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Ilya Yaroshenko via Digitalmars-d
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

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Ilya Yaroshenko via Digitalmars-d
On Thursday, 29 September 2016 at 18:53:26 UTC, Andrei Alexandrescu wrote: On 09/29/2016 02:37 PM, Ilya Yaroshenko wrote: On Thursday, 29 September 2016 at 17:56:59 UTC, Stefan Koch wrote: Solution T[] can be added to a template variadic name. ``` void foo(size_t[] Index...)(Indexes index) {

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Steven Schveighoffer via Digitalmars-d
On 9/29/16 2:49 PM, Stefan Koch wrote: On Thursday, 29 September 2016 at 18:37:36 UTC, Ilya Yaroshenko wrote: On Thursday, 29 September 2016 at 17:56:59 UTC, Stefan Koch wrote: Solution T[] can be added to a template variadic name. ``` void foo(size_t[] Index...)(Indexes index) { ... }

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Andrei Alexandrescu via Digitalmars-d
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. --

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Ilya Yaroshenko via Digitalmars-d
On Thursday, 29 September 2016 at 18:49:45 UTC, Stefan Koch wrote: On Thursday, 29 September 2016 at 18:37:36 UTC, Ilya Yaroshenko wrote: On Thursday, 29 September 2016 at 17:56:59 UTC, Stefan Koch wrote: Solution T[] can be added to a template variadic name. ``` void foo(size_t[]

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Andrei Alexandrescu via Digitalmars-d
On 09/29/2016 02:37 PM, Ilya Yaroshenko wrote: On Thursday, 29 September 2016 at 17:56:59 UTC, Stefan Koch wrote: Solution T[] can be added to a template variadic name. ``` void foo(size_t[] Index...)(Indexes index) { ... } ``` This description does not tell me anything. Current

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Stefan Koch via Digitalmars-d
On Thursday, 29 September 2016 at 18:37:36 UTC, Ilya Yaroshenko wrote: On Thursday, 29 September 2016 at 17:56:59 UTC, Stefan Koch wrote: Solution T[] can be added to a template variadic name. ``` void foo(size_t[] Index...)(Indexes index) { ... } ``` This description does not tell me

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Ilya Yaroshenko via Digitalmars-d
On Thursday, 29 September 2016 at 17:56:59 UTC, Stefan Koch wrote: Solution T[] can be added to a template variadic name. ``` void foo(size_t[] Index...)(Indexes index) { ... } ``` This description does not tell me anything. Current template argument can be declared as `(Index...)`.

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Stefan Koch via Digitalmars-d
On Thursday, 29 September 2016 at 17:24:55 UTC, Ilya Yaroshenko wrote: Problem Most ndslice API accepts variadic list of integers. The following code example shows how `slice` and `[a, b, c]` can generate 64 identical functions each. ``` // (1, 1U, 1UL, 1L) x // (2, 2U, 2UL, 2L) x // (3, 3U,

Re: DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Ilya Yaroshenko via Digitalmars-d
https://github.com/libmir/mir/wiki/Compiler-and-druntime-bugs#dips

DIP Mir1 Draft: Variadic template parameters with the same time.

2016-09-29 Thread Ilya Yaroshenko via Digitalmars-d
Problem Most ndslice API accepts variadic list of integers. The following code example shows how `slice` and `[a, b, c]` can generate 64 identical functions each. ``` // (1, 1U, 1UL, 1L) x // (2, 2U, 2UL, 2L) x // (3, 3U, 3UL, 3L) = 4 ^^ 3 = 64 identical variants auto cube = slice!double(1, 2,