What is the stance on partial initializers when declaring multiplevariables of the same type?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Jul 22 07:59:10 PDT 2011
On 7/22/11 4:43 AM, kenji hara wrote:
> 2011/7/22 Andrei Alexandrescu<SeeWebsiteForEmail at erdani.org>:
> I have posted a pull request for expanding alias this tuples somewhere.
> https://github.com/D-Programming-Language/dmd/pull/74
Great! I made a comment on
http://d.puremagic.com/issues/show_bug.cgi?id=2779, please let me know
if you agree. Fixing http://d.puremagic.com/issues/show_bug.cgi?id=2781
seems fine as there's no ambiguity there.
> I think that this patch will make conversion seamlessly from built-in
> tuple to library tuple.
>
>> auto (i, f) = tuple(5, 2.2);
>> Walter and I discussed a language change to allow that.
>
> I'd like to make patch supporting it.
Sounds great. The way Walter and I wanted to spec that would be as a
simple syntactic rewrite. This construct:
auto (a1, a2, ..., aN) = x;
is expanded mechanically to:
static assert(x.length == N, "Too many elements in definition");
auto a1 = x[0];
auto a2 = x[1];
...
auto aN = x[N-1];
This ensures that the feature works with statically-sized arrays and
std.Tuple, but also with other types that define the required
operations. There's no special casing of library artifacts.
If x is an expression, it must be evaluated only once.
Let's discuss things here and hear from Walter before you embark on
doing this.
Andrei
More information about the Digitalmars-d
mailing list