Boost logo

Boost :

From: Sam Partington (sam.partington_at_[hidden])
Date: 2005-10-19 05:48:45


On 10/18/05, Fernando Cacciola <fernando_cacciola_at_[hidden]> wrote:
> > I must admit I find the whole rebinding interface very ambiguous.
> Just to keep the discussion clear, is a matter of semantics not interface.

Yes, but thats just a matter of semantics itself :-)
(Of course you're right)

> > What we have is a reference that is potentially null.
> > In my mind that is a pointer (wrapped up obviously),
> > and not an optional at all.
>
> Maybe you meant "not a reference at all"?
> Well, in optional<> this is implemented as a true reference, not as a
> pointer like in reference_wrapper().
> So is more like that there is a reference or nothing.

I understand that. What I meant was that in any situation that I
might conceivably use an optional<T&> I would use a (wrapped) pointer.
It feels like we're trying to find a solution for something that
already exists in the language, AND is already well understood by
everyone (ie T*). However, I accept your next argument...

> > That this discussion is going on so long and is so disputed it seems
> > to me that there is no right-way, and the best way of fixing it is to
> > disallow T& altogether.
> >
> This is one choice, yes.
> I hope we can solve it because dorpping T& totally breaks generic
> programming.

Yes, I can see that this is an important point. But I would like to
see an example of where one might do so (I know thats difficult as by
its very nature it would be generic).

> > But if it were to stay I would say that the rebinding is very
> > surpising for someone used to using references.
>
> And so is the no-rebinding alternative.
> Look for _my_ thought experiment in another pos.
> Do it yourself, show it to your mate, and share with me the results.

I have done, and that result surprised me too. My point is that if
both behaviours lead to surprising results then disambiguate them by
making all such operations explicit in their usage, and remove the
ambiguous implicit usage.

However, it looks like we agree on that, so I won''t go on any more about it.

> Is it totally clear to everyone that this rebinds?
> o = optional<int&>(i);

To me yes absolutely.

> Now I wonder, if instead of operator*, we used value() (or whatever), would
> it be just as clear?

Hmm, I not sure on that one. Personally I like the pointer interface.
 I have several utility/wrapper classes that use dereference to get at
the underlying type, and I'm quite accustomed to the concept/syntaxt.
I have no problem with operator* returning a raw reference or a proxy
type that will do the assignment itself.

But an ordinary function returning a raw reference that might be
invalid could be quite unexpected.

I guess that depends on whether the pointer interface is agreed upon or not...

Sam


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk