iota to array
psychoticRabbit
meagain at meagain.com
Sun Feb 25 06:22:03 UTC 2018
On Sunday, 25 February 2018 at 05:40:19 UTC, Jonathan M Davis
wrote:
>
> int[] intArr = iota(1, 11).array();
>
>
> - Jonathan M Davis
thanks!
oh man. It's so easy to do stuff in D ;-)
But this leads me to a new problem now.
When I run my code below, I get ints printed instead of doubles??
---------------------
module test;
import std.stdio : writeln;
import std.traits : isArray;
import std.array : array;
import std.range : iota;
void main()
{
int[] intArr = iota(1, 11).array(); // 1..10
double[] doubleArr = iota(1.0, 11.0).array(); // 1.0..10.0
char[] charArr = iota('a', '{').array(); // a..z
printArray(intArr);
printArray(doubleArr); // why is it printing ints instead of
doubles??
printArray(charArr);
}
void printArray(T)(const ref T[] a) if (isArray!(T[]))
{
foreach(t; a)
writeln(t);
}
---------------------------------
More information about the Digitalmars-d-learn
mailing list