Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
March 28, 2019 Simultaneously assigning to all values in a tuple | ||||
---|---|---|---|---|
| ||||
Is it possible to assign to all values in a tuple at once if they are the same type? I.e. Tuple!(double, "x", double, "y") t; t[] = 1.0; |
March 30, 2019 Re: Simultaneously assigning to all values in a tuple | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jamie | On 3/27/19 8:29 PM, Jamie wrote:
> Is it possible to assign to all values in a tuple at once if they are
> the same type?
> I.e.
>
> Tuple!(double, "x", double, "y") t;
> t[] = 1.0;
>
foreach (ref member; t.expand) {
member = 1.0;
}
|
April 01, 2019 Re: Simultaneously assigning to all values in a tuple | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jamie | On 2019-03-28 01:29, Jamie wrote: > Is it possible to assign to all values in a tuple at once if they are the same type? > I.e. > > Tuple!(double, "x", double, "y") t; > t[] = 1.0; > Yes: Tuple!(double, "x", double, "y") t; t.expand = AliasSeq!(3.1, 4.2); -- /Jacob Carlborg |
April 01, 2019 Re: Simultaneously assigning to all values in a tuple | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Monday, 1 April 2019 at 09:46:34 UTC, Jacob Carlborg wrote:
> On 2019-03-28 01:29, Jamie wrote:
>> Is it possible to assign to all values in a tuple at once if they are the same type?
>> I.e.
>>
>> Tuple!(double, "x", double, "y") t;
>> t[] = 1.0;
>>
>
> Yes:
>
> Tuple!(double, "x", double, "y") t;
> t.expand = AliasSeq!(3.1, 4.2);
Since the question was how to assign to all values in a tuple:"
t.expand = Repeat!(2, 1.0);
--
Simen
|
April 01, 2019 Re: Simultaneously assigning to all values in a tuple | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjærås | On Monday, 1 April 2019 at 10:12:50 UTC, Simen Kjærås wrote:
> On Monday, 1 April 2019 at 09:46:34 UTC, Jacob Carlborg wrote:
>> On 2019-03-28 01:29, Jamie wrote:
>>> Is it possible to assign to all values in a tuple at once if they are the same type?
>>> I.e.
>>>
>>> Tuple!(double, "x", double, "y") t;
>>> t[] = 1.0;
>>>
>>
>> Yes:
>>
>> Tuple!(double, "x", double, "y") t;
>> t.expand = AliasSeq!(3.1, 4.2);
>
> Since the question was how to assign to all values in a tuple:"
>
> t.expand = Repeat!(2, 1.0);
t.expand = Repeat!(t.length, 1.0);
|
Copyright © 1999-2021 by the D Language Foundation