tuple slicing operator
Vlad Levenfeld via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Aug 9 09:39:32 PDT 2014
I may be misunderstanding the intended semantics of the []
operator but I've come to interpret x[] to mean "give me x as a
range" and this is the meaning I intend when I overload it in my
own structs.
But -
auto z = tuple (1,1,1);
pragma (msg, typeof(z)); // Tuple!(int, int, int)
pragma (msg, typeof(z[])); // (int, int, int)
I'm surprised by what the last line outputs.
In generic code I tend to use [] to make sure a variable is a
range before I use it (like static arrays, or structs following
my interpretation of []). So now whenever tuples might come into
the mix I have to pass the argument through an overloaded
convenience function that can tell a range or tuple type from
one-element variadic argument.
I've got a lot of difficulty with that last part so I am
wondering, is there a better way to do this?
More information about the Digitalmars-d-learn
mailing list