int v[1];
auto p1 = v;
auto &p2 = v;
auto *p3 = v;
p1
is of type int *
(same for p3
). Particularly at this trivial sample I find p2
( int (&)[1]
) more useful since it inherents array semantics, e.g. I can apply sizeof
on p2
to give the same as sizeof
on v
.
Is there a standard quotation regarding that?
Why defaulting to references is a bad idea? (for this arrays case I mean, almost no c++ programmer cares about them these days anyway...)
I believe it's for consistency with non-template functions. Arrays undergo the array-to-pointer conversion anytime they're accessed, except when being bound to a reference. So with the existing rules, the following are consistent:
and