Jump to page: 1 2 3
Thread overview
DIP Mir1 Draft: Variadic template parameters with the same time.
Sep 29, 2016
Ilya Yaroshenko
Sep 29, 2016
Ilya Yaroshenko
Sep 29, 2016
Stefan Koch
Sep 29, 2016
Ilya Yaroshenko
Sep 29, 2016
Stefan Koch
Sep 29, 2016
Ilya Yaroshenko
Sep 29, 2016
Ilya Yaroshenko
Sep 29, 2016
Ilya Yaroshenko
Sep 29, 2016
Ilya Yaroshenko
Sep 29, 2016
Timothee Cour
Sep 29, 2016
Ilya Yaroshenko
Sep 29, 2016
Timothee Cour
Sep 29, 2016
Ilya Yaroshenko
Sep 29, 2016
Ilya Yaroshenko
Sep 29, 2016
pineapple
Sep 29, 2016
Ilya Yaroshenko
Sep 29, 2016
Walter Bright
Sep 29, 2016
Ilya Yaroshenko
Sep 29, 2016
ag0aep6g
Sep 29, 2016
Ilya Yaroshenko
Sep 29, 2016
Ilya Yaroshenko
Sep 29, 2016
ag0aep6g
Sep 29, 2016
Ilya Yaroshenko
September 29, 2016
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, 3);

size_t i;
sizediff_t j;
int k;
uint p;
// 64 identical variants for 64-bit with i, j, k, p
auto v = cube[i, j, k];
```
------------------------

Solution

T[] can be added to a template variadic name.

```
void foo(size_t[] Index...)(Indexes index)
{
    ...
}
```
September 29, 2016
https://github.com/libmir/mir/wiki/Compiler-and-druntime-bugs#dips
September 29, 2016
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, 3UL, 3L) = 4 ^^ 3 = 64 identical variants
> auto cube = slice!double(1, 2, 3);
>
> size_t i;
> sizediff_t j;
> int k;
> uint p;
> // 64 identical variants for 64-bit with i, j, k, p
> auto v = cube[i, j, k];
> ```
> ------------------------
>
> Solution
>
> T[] can be added to a template variadic name.
>
> ```
> void foo(size_t[] Index...)(Indexes index)
> {
>     ...
> }
> ```

This description does not tell me anything.
September 29, 2016
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...)`.
The solutions just allows to specify the type `(size_t[] Index...)`
September 29, 2016
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 anything.
>
> Current template argument can be declared as `(Index...)`.
> The solutions just allows to specify the type `(size_t[] Index...)`

I think we already have typesafe variadics.
What do you want to change ?
September 29, 2016
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 template argument can be declared as `(Index...)`.
> The solutions just allows to specify the type `(size_t[] Index...)`

This feature exists. What am I missing? -- Andrei
September 29, 2016
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[] Index...)(Indexes index)
>>>> {
>>>>     ...
>>>> }
>>>> ```
>>>
>>> This description does not tell me anything.
>>
>> Current template argument can be declared as `(Index...)`.
>> The solutions just allows to specify the type `(size_t[] Index...)`
>
> I think we already have typesafe variadics.

Only for runtime arguments.

> What do you want to change ?

`(Index...)` -> `(size_t[] Index...)` // this is about template arguments, not runtime


September 29, 2016
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

September 29, 2016
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)
>>>> {
>>>>     ...
>>>> }
>>>> ```
>>>
>>> This description does not tell me anything.
>>
>> Current template argument can be declared as `(Index...)`.
>> The solutions just allows to specify the type `(size_t[] Index...)`
>
> I think we already have typesafe variadics.
> What do you want to change ?

typesafe variadics as runtime parameters, not compile-time parameters.

-Steve
September 29, 2016
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)
>>>> {
>>>>     ...
>>>> }
>>>> ```
>>>
>>> This description does not tell me anything.
>>
>> Current template argument can be declared as `(Index...)`.
>> The solutions just allows to specify the type `(size_t[] Index...)`
>
> This feature exists. What am I missing? -- Andrei

No, it does not
---
, void foo(size_t[] I...)(I i)
{
	
}

void main()
{
	foo(1, 2, 3);
}
---
/d812/f719.d(1): Error: found '...' when expecting ')'
/d812/f719.d(1): Error: found ')' when expecting '('
/d812/f719.d(1): Error: basic type expected, not (
/d812/f719.d(1): Error: function declaration without return type. (Note that constructors are always named 'this')
/d812/f719.d(2): Error: found '{' when expecting ')'
/d812/f719.d(4): Error: semicolon expected following function declaration
/d812/f719.d(4): Error: unrecognized declaration

« First   ‹ Prev
1 2 3