Feature Request for 2.0: A way to implement MRV
Jari-Matti Mäkelä
jmjmak at utu.fi.invalid
Fri Aug 31 11:37:46 PDT 2007
Downs wrote:
> I don't think this much-longed-for feature (returning tuples) has been
> mentioned at DCon, and although I believe it would
> be highly useful, I realize it might be too hard to implement (though I
> can't exactly see how, if a half-working surrogate can be whipped up
> with half a page of 1.0 code).
> However, there is an easier way to achieve something sufficiently close
> as to be indistuingishable from "real" MRV. This way entails two closely
> related features:
>
> First, the redefinition of the comma operator to combine variables into
> a new type of tuple: a variable tuple, that being a set of variables
> combined under a common name, that a tuple can be assigned to.
>
> Second, and probably more important, the ability to implicit cast a
> struct to a tuple.
>
> This would allow us to extend the current solution of returning a
> TupleStruct to implicitly assigning that tuple struct to a group of
> variables without needing to store their pointers separately, as is
> currently done.
votes++;
http://d.puremagic.com/issues/show_bug.cgi?id=1293
What makes me a bit worried is that the 'future of D' slides didn't say much
about tuples. It's a natural extension to the current type system and
improves the readability of code (and hopefully also deprecates those
ad-hoc implementations with templates that actually are an order of
magnitude slower than e.g. out parameters). It's also one area where D
could "win" C++0x:
tuple<int, int> get_coordinates_of_collision() {
...
return make_tuple(x, y);
}
vs for example
(int, int) get_coordinates_of_collision() {
...
return x, y;
}
or
tmp = x;
x = y;
y = tmp;
vs
x, y = y, x;
Of course there are useful use cases for metaprogramming too.
More information about the Digitalmars-d
mailing list