auto*
Meta via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jul 6 17:39:32 PDT 2017
On Thursday, 6 July 2017 at 23:51:13 UTC, H. S. Teoh wrote:
> On Thu, Jul 06, 2017 at 11:50:24PM +0000, bauss via
> Digitalmars-d wrote: [...]
>> Let's say you have.
>>
>> auto a = foo();
>>
>> You have no idea what auto actually is in that case, but
>>
>> auto* a = foo();
>>
>> You know auto is a pointer of whatever foo returns.
>
> Ah, I see. So if foo() doesn't return a pointer it will be a
> compile error? So it's basically a kind of self-documentation?
>
>
> T
Kenji also extended the inference to some very interesting cases.
// static array type
int[$] a1 = [1,2]; // int[2]
auto[$] a2 = [3,4,5]; // int[3]
const[$] a3 = [6,7,8]; // const(int[3])
// dynamic array type
immutable[] a4 = [1,2]; // immutable(int)[]
shared[] a5 = [3,4,5]; // shared(int)[]
// partially specified part is unqualified.
// pointer type
auto* p1 = new int(3); // int*
const* p2 = new int(3); // const(int)*
// mixing
auto[][$] x1 = [[1,2,3],[4,5]]; // int[][2]
shared*[$] x2 = [new int(1), new int(2)]; // shared(int)*[2]
(https://github.com/dlang/dmd/pull/3615)
Of course this could also get confusing pretty fast. I wish we at
least had the `int[$]` syntax but it's not a huge loss.
More information about the Digitalmars-d
mailing list