auto*
Patrick Schluter via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jul 6 22:19:37 PDT 2017
On Thursday, 6 July 2017 at 20:24:24 UTC, FoxyBrown wrote:
> On Thursday, 6 July 2017 at 18:11:13 UTC, H. S. Teoh wrote:
>> On Thu, Jul 06, 2017 at 06:10:57PM +0000, FoxyBrown via
>> Digitalmars-d wrote:
>>> Create an auto pointer, handy in some cases and fits in the
>>> language as a natural generalization.
>>
>> What's an auto pointer?
>>
>>
>> T
>
> is it not obvious?
>
> auto x = ...
>
> auto* x = ...
>
> auto* is the pointerized version of auto.
>
>
> e.g.,
>
> int x = ...
>
> int* x = ...
>
> typeof(x) y = ...
> typeof(x)* y = ...
>
>
> obviously the rhs must be congruent with the type.
>
> auto p = &foo; // a pointer
> auto* p = &foo; // a double pointer to foo.
>
> When having the need to require a pointer to a pointer, it
> avoids having to specify the type in a verbose way.
>
> i.e., the second line above is not valid, but to do it we must
> either cast to void** or use typeof and such to get the correct
> type and make a pointer out of it. auto* simplifies all that.
Just one thing. auto in D is not a type, it's a storage class. It
inherited that from C. This means auto* doesn't make any sense as
the * is part of a type. So your expression lack a proper type.
Type deduction works by using the type of the rhs of the
expression and applying to it the storage class of the lhs. This
means that
auto x = ..; works
but also
static x = ..; works
D does not implemented C's register storage class, but if it did
register x = .. would also work.
When you understand that you will understand why your proposition
does not make sense.
More information about the Digitalmars-d
mailing list