www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - int-double auto array

reply "Dennis Ritchie" <dennis.ritchie mail.ru> writes:
Hi.
To create int-double array I have to pre-initialize the auto 
array:

import std.stdio;
import std.algorithm;

void main() {

	auto s = [5.31, 6];

	s = s.remove(0, 1);

	double k;

	readf("%s", &k); // 17.32

	s ~= k, s ~= 5, s ~= 1.125;

	writeln(s); // [17.32, 5, 1.125]
}

I can do it something like this (without initialization)?

import std.stdio;

void main() {

	auto s = []; // wrong

	double k;

	readf("%s", &k); // 17.32

	s ~= k, s ~= 5, s ~= 1.125;

	writeln(s); // [17.32, 5, 1.125]
}
Mar 17 2015
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Wednesday, 18 March 2015 at 03:54:01 UTC, Dennis Ritchie wrote:
 Hi.
 To create int-double array I have to pre-initialize the auto 
 array:
There's no such thing as an int double array, what you made there is just a double[]. The ints are converted to double when added to that array. So you can just do double[] s;
Mar 17 2015
parent "Dennis Ritchie" <dennis.ritchie mail.ru> writes:
On Wednesday, 18 March 2015 at 04:00:04 UTC, Adam D. Ruppe wrote:
 So you can just do

 double[] s;
Thanks. Yes, I overthink everything :)
Mar 17 2015