C++ Logo

SG12

Advanced search

Subject: Re: [isocpp-lib-ext] (draft) The simple truth about references
From: Ville Voutilainen (ville.voutilainen_at_[hidden])
Date: 2020-02-07 01:28:54


On Fri, 7 Feb 2020 at 09:05, Herb Sutter via Lib-Ext
<lib-ext_at_[hidden]> wrote:
> Aren't local references useful to express aliases, for example to a member of an array or container?
>
> Yes. Pointers can do it equivalently, it's a style choice.
>
> For example, this local reference is useful:
>
> int& r = a[f(i)];
>
> // ... then use r repeatedly ...
>
> Or you can equivalently use a pointer:
>
> int* p = a[f(i)];
>
> // ... then use *p repeatedly ...

Is that latter line intended to be
int* p = &a[f(i)];
?


SG12 list run by herb.sutter at gmail.com