Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-12-12 15:31:51


From: "Fernando Cacciola" <fernando_cacciola_at_[hidden]>
> From: "Peter Dimov" <pdimov_at_[hidden]>
[...]
> > if(both uninitialized)
> > {
> > // do nothing, nothrow
> > }
> > else if(one initialized, one not)
> > {
> > lhs.reset(*rhs); // strong
> > rhs.reset(); // nothrow
> > }
> > else // both initialized
> > {
> > using std::swap;
> > swap(*lhs, *rhs);
> > }
> >
> > It doesn't even need friendship.
> >
> I see.
> Q: This code is supposed to be in boost::swap( optional<T>&,
optional<T>&)?

Yep.

> > void f(optional<T> /*const &*/ opt);
> >
> > is different than
> >
> > void f(T const * pt);
> >
> > as the latter might potentially store 'pt' while the former cannot.
> >
> ? You mean that the code inside f() could hold onto 'pt'?
> Well, yes it can... but that would be nasty.
> It is supposed to know that ownership is not being handed in.
> The use of a pointer is reserved to convey optionality.

No, functions that store an address use by-pointer, too, even when it must
not be NULL. Consider:

void f(int const & r); // stores &r

f(5L);

> If I have:
>
> void foo ( optional<T> x, optional<T> y )
> {
> ( x == y ) ;
> }
>
> Why do you suggest to be the semantic of the comnparison?
>
> I think that you suggest that it is:
>
> ( (!x) != (!y) ? false : ( !x ? true : ( *x == *y ) )
>
> but in this case, replacing optional<T> with T* changes this semantic,
which
> is what I object.
>
> OTOH, my definition as: get_pointer(x) == get_pointer(y)
>
> will not change the semantic of the comparison if optional<T> is replaced
by
> T*

Yes it will. :-)

optional<T> m;

foo(m, m); // comparison inside yields false

T * p;

foo(p, p); // comparison inside yields true


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