Boost logo

Boost :

Subject: Re: [boost] Is there any interest in non-owning pointer-like types?
From: Joseph Thomson (joseph.thomson_at_[hidden])
Date: 2017-02-01 07:12:16

On 1 Feb 2017 7:51 p.m., "Olaf van der Spek" <ml_at_[hidden]> wrote:

On Wed, Feb 1, 2017 at 12:39 PM, Oswin Krause
<Oswin.Krause_at_[hidden]> wrote:
> On 2017-02-01 12:02, Olaf van der Spek wrote:
>> On Wed, Feb 1, 2017 at 11:24 AM, Oswin Krause
>> <Oswin.Krause_at_[hidden]> wrote:
>>> For me, the biggest problem of the proposal is that observer_ptr<T> is
>>> implicitely constructed from T&. In my code I often use:
>>> Foo a;
>>> Bar b(&a);//&a signals that b only references to a, but does not copy
>>> Now, when I write
>>> Bar b(a); //so is a now copied?
>>> While the interface is clearer in documentation, the usage is less
>> IMO using pointers instead of references to indicate something isn't
>> copied is bad practice.. the language is C++, not C.
> This is not a C vs C++ thing.
> But assume it was. How would you indicate that in C++? It should be clear
> without looking at the reference whether it is okay for a to go out of
> before b or not.

There's no way to indicate that, AFAIK.

The way to indicate it is to require explicit conversion from `T&` to your
pointer-like type. `make_observer` can play the role of a type-safe `&`. I
would be happy to remove implicit conversion from `T&` if it is agreed to
be undesirable.


Boost list run by bdawes at, gregod at, cpdaniel at, john at