| Thread overview | |||||
|---|---|---|---|---|---|
|
March 18, 2015 int-double auto array | ||||
|---|---|---|---|---|
| ||||
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]
}
| ||||
March 18, 2015 Re: int-double auto array | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Dennis Ritchie | 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;
| |||
March 18, 2015 Re: int-double auto array | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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 :)
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply