www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Data structures of mixed type

reply Russel Winder via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
What is the idiomatic way of having an array with a mix of int and
float data?

Is relying on automated conversion of int to float acceptable?

--=20
Russel.
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder ekiga.n=
et
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
Sep 08 2016
parent Andrea Fontana <nospam example.com> writes:
On Thursday, 8 September 2016 at 08:56:13 UTC, Russel Winder 
wrote:
 What is the idiomatic way of having an array with a mix of int 
 and float data?
Maybe https://dlang.org/phobos/std_variant.html#.Algebraic ?
 Is relying on automated conversion of int to float acceptable?
I don't think so: import std.stdio; void main() { int i = 12345678; float f = i; writeln(f); } Andrea
Sep 08 2016