Converting array in to aliased tuple type.

visitor visitor at gmail.com
Mon Dec 25 21:10:02 UTC 2017


On Monday, 25 December 2017 at 17:59:54 UTC, visitor wrote:
> On Monday, 25 December 2017 at 15:03:08 UTC, aliak wrote:
>> On Monday, 25 December 2017 at 14:08:08 UTC, Mengu wrote:
>>>
>> I was kind of hoping for some magical D variadic alias 
>> template on Tuple or something that will just deconstruct the 
>> arguments in to tuple components.
>
> i don't think it's better but :
>
> https://run.dlang.io/is/2rgOzh

oops sorry, compile time ...

import std.stdio, std.string, std.algorithm, std.conv, std.range;
import std.typecons;

alias Point = Tuple!(int, "x", int, "y");
enum data = "1,2:8,9";

auto points = data.split(':')
                   .map!( a => a.split(',').map!(to!int).array )
                   .map!( (da) {
                       int[2] staticArray;
                       foreach (i, el; da)
                           staticArray[i] = el;
                       return staticArray;
                   } )
                   .map!Point ;

void main()
{
     writefln("points : %s", points);
}


More information about the Digitalmars-d-learn mailing list