specifying an auto array type

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Dec 26 23:40:55 PST 2015


On 12/26/2015 09:45 PM, Jay Norwood wrote:

 > This is getting kind of a long example,

There are issues with that code that make it hard for me to guess the 
intent.

 > a way to have the Tuple array defined as auto instead of having to 
specify
 > the types.  I tried using .array() at the end of the last 
samples.each!, but
 > couldn't find an implementation that worked.

It looks like you need map(), not each():

import std.algorithm;
import std.typecons;
import std.array;

void main() {
     auto a = [ 1, 2 ];
     auto arr = a.map!(e => tuple(2 * e, e * e)).array;

     static assert(is(typeof(arr) == Tuple!(int, int)[]));
}

Ali



More information about the Digitalmars-d-learn mailing list