digitalmars.D.learn - turn range into tuple ?
- Flaze07 (8/8) Jun 28 2018 is there some sort of ways to turn range into tuple ? ( an array
- Stefan Koch (2/10) Jun 28 2018 I think you are looking for `aliasSeqOf` in std.meta
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (4/12) Jun 28 2018 https://dlang.org/phobos/std_meta#aliasSeqOf
- Flaze07 (2/14) Jun 28 2018 what about during runtime ?
- Stefan Koch (3/19) Jun 28 2018 Tuples are compile-time entities.
- Flaze07 (2/22) Jun 28 2018 that's interesting, thanks
- Flaze07 (5/28) Jun 28 2018 the reason I am asking is that I want to do something similar to
- Jonathan M Davis (9/26) Jun 28 2018 Ranges in general have an arbitrary length, whereas tuples have a fixed
- Flaze07 (2/17) Jun 28 2018 ok gotcha
is there some sort of ways to turn range into tuple ? ( an array preferably ) e.g uint[] arr = [ 10, 20, 30 ]; auto tup = rangeToTup( arr ); assert( tup[ 0 ] == 10 ); assert( tup[ 1 ] == 20 ); assert( tup[ 2 ] == 30 );
Jun 28 2018
On Thursday, 28 June 2018 at 08:36:54 UTC, Flaze07 wrote:is there some sort of ways to turn range into tuple ? ( an array preferably ) e.g uint[] arr = [ 10, 20, 30 ]; auto tup = rangeToTup( arr ); assert( tup[ 0 ] == 10 ); assert( tup[ 1 ] == 20 ); assert( tup[ 2 ] == 30 );I think you are looking for `aliasSeqOf` in std.meta
Jun 28 2018
On Thursday, 28 June 2018 at 08:36:54 UTC, Flaze07 wrote:is there some sort of ways to turn range into tuple ? ( an array preferably ) e.g uint[] arr = [ 10, 20, 30 ]; auto tup = rangeToTup( arr ); assert( tup[ 0 ] == 10 ); assert( tup[ 1 ] == 20 ); assert( tup[ 2 ] == 30 );https://dlang.org/phobos/std_meta#aliasSeqOf -- Simen
Jun 28 2018
On Thursday, 28 June 2018 at 08:52:33 UTC, Simen Kjærås wrote:On Thursday, 28 June 2018 at 08:36:54 UTC, Flaze07 wrote:what about during runtime ?is there some sort of ways to turn range into tuple ? ( an array preferably ) e.g uint[] arr = [ 10, 20, 30 ]; auto tup = rangeToTup( arr ); assert( tup[ 0 ] == 10 ); assert( tup[ 1 ] == 20 ); assert( tup[ 2 ] == 30 );https://dlang.org/phobos/std_meta#aliasSeqOf -- Simen
Jun 28 2018
On Thursday, 28 June 2018 at 09:26:10 UTC, Flaze07 wrote:On Thursday, 28 June 2018 at 08:52:33 UTC, Simen Kjærås wrote:Tuples are compile-time entities. However if you just want an array use std.range.array.On Thursday, 28 June 2018 at 08:36:54 UTC, Flaze07 wrote:what about during runtime ?is there some sort of ways to turn range into tuple ? ( an array preferably ) e.g uint[] arr = [ 10, 20, 30 ]; auto tup = rangeToTup( arr ); assert( tup[ 0 ] == 10 ); assert( tup[ 1 ] == 20 ); assert( tup[ 2 ] == 30 );https://dlang.org/phobos/std_meta#aliasSeqOf -- Simen
Jun 28 2018
On Thursday, 28 June 2018 at 09:38:36 UTC, Stefan Koch wrote:On Thursday, 28 June 2018 at 09:26:10 UTC, Flaze07 wrote:that's interesting, thanksOn Thursday, 28 June 2018 at 08:52:33 UTC, Simen Kjærås wrote:Tuples are compile-time entities. However if you just want an array use std.range.array.On Thursday, 28 June 2018 at 08:36:54 UTC, Flaze07 wrote:what about during runtime ?is there some sort of ways to turn range into tuple ? ( an array preferably ) e.g uint[] arr = [ 10, 20, 30 ]; auto tup = rangeToTup( arr ); assert( tup[ 0 ] == 10 ); assert( tup[ 1 ] == 20 ); assert( tup[ 2 ] == 30 );https://dlang.org/phobos/std_meta#aliasSeqOf -- Simen
Jun 28 2018
On Thursday, 28 June 2018 at 09:42:54 UTC, Flaze07 wrote:On Thursday, 28 June 2018 at 09:38:36 UTC, Stefan Koch wrote:the reason I am asking is that I want to do something similar to this code in python : a, b, c = input().split(' ') because I feel like reading with readln is easier than readfOn Thursday, 28 June 2018 at 09:26:10 UTC, Flaze07 wrote:that's interesting, thanksOn Thursday, 28 June 2018 at 08:52:33 UTC, Simen Kjærås wrote:Tuples are compile-time entities. However if you just want an array use std.range.array.On Thursday, 28 June 2018 at 08:36:54 UTC, Flaze07 wrote:what about during runtime ?is there some sort of ways to turn range into tuple ? ( an array preferably ) e.g uint[] arr = [ 10, 20, 30 ]; auto tup = rangeToTup( arr ); assert( tup[ 0 ] == 10 ); assert( tup[ 1 ] == 20 ); assert( tup[ 2 ] == 30 );https://dlang.org/phobos/std_meta#aliasSeqOf -- Simen
Jun 28 2018
On Thursday, June 28, 2018 09:26:10 Flaze07 via Digitalmars-d-learn wrote:On Thursday, 28 June 2018 at 08:52:33 UTC, Simen Kjærås wrote:Ranges in general have an arbitrary length, whereas tuples have a fixed length that is known at compile time. So, it really doesn't make sense to convert a range to a tuple. You can create function that takes the first x number of elements of a range (probably throwing if the range is too short) and create a tuple from those elements, but it would be a bit of a pain to do, and it would generally be a pretty weird thing to do. A dynamic array would make a lot more sense than a tuple. - Jonathan M DavisOn Thursday, 28 June 2018 at 08:36:54 UTC, Flaze07 wrote:what about during runtime ?is there some sort of ways to turn range into tuple ? ( an array preferably ) e.g uint[] arr = [ 10, 20, 30 ]; auto tup = rangeToTup( arr ); assert( tup[ 0 ] == 10 ); assert( tup[ 1 ] == 20 ); assert( tup[ 2 ] == 30 );https://dlang.org/phobos/std_meta#aliasSeqOf -- Simen
Jun 28 2018
On Thursday, 28 June 2018 at 09:47:07 UTC, Jonathan M Davis wrote:On Thursday, June 28, 2018 09:26:10 Flaze07 via Digitalmars-d-learn wrote:ok gotchaOn Thursday, 28 June 2018 at 08:52:33 UTC, Simen Kjærås wrote:Ranges in general have an arbitrary length, whereas tuples have a fixed length that is known at compile time. So, it really doesn't make sense to convert a range to a tuple. You can create function that takes the first x number of elements of a range (probably throwing if the range is too short) and create a tuple from those elements, but it would be a bit of a pain to do, and it would generally be a pretty weird thing to do. A dynamic array would make a lot more sense than a tuple. - Jonathan M Davis[...]what about during runtime ?
Jun 28 2018