Generic array
Jonathan M Davis
jmdavisProg at gmx.com
Thu Nov 17 15:07:47 PST 2011
On Thursday, November 17, 2011 14:41 RenatoL wrote:
> Ok, tk u all.
> I guess this is a very poor approach if we are looking for
> performance
Mixing types like that in an array is not a normal thing to do. However, if
you're looking to hold a specific number of items of diverse types
(particularly if there's only a few of them), you can look at
std.typecons.Tuple.
In that case, you'd do something like
auto t = tuple(0, "aa", 2.4);
And you don't have to query about the type information that way, because it's
part of the type - Tuple!(int, string, float). Then you can index like you
would an array.
auto a = t[0];
auto b = t[1];
auto c = t[2];
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list