Type inference in array literals

bearophile bearophileHUGS at lycos.com
Sat Aug 28 13:19:02 PDT 2010


Jesse Phillips:

> D uses the last element in the array literal to select the type.

That's not true, this doesn't assert:

import std.stdio: writeln;
void main() {
    auto a = [1, 1.5, 2];
    assert(is(typeof(a) == double[]));
}

I think it uses ?: on all elements, to infer the type.

Bye,
bearophile


More information about the Digitalmars-d mailing list