Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-01-23 18:02:50


"Peter Dimov" <pdimov_at_[hidden]> wrote in message
news:025201c3e1fb$e9396700$1d00a8c0_at_pdimov2...
> Howard Hinnant wrote:
> > On Jan 23, 2004, at 3:13 PM, Jonathan Turkanis wrote:
> >
> >> What is your view on conversions which add cv-qualification?
> >
> > As long as your asking... ;-)
> >
> > I see no problem with:
> >
> > move_ptr<T> p;
> > move_ptr<const T> pc(move(p));
> >
> > but not vice-versa (just like raw pointers).
>
> The question is, I suspect, about the array case:
>
> move_ptr<T[]> p;
> move_ptr<T const []> pc( move(p) );
>
> since the one above is already covered by the "usual" converting
> constructor.

Yes, this is what I meant. In the case of pointers to objects, the
templated constructor defers to the usual conversion rules for
pointer. For arrays, however, if you omit the templated contructor,
you loose the conversions that add cv-qualifications.

How to correct this, if these conversions are desirable (I think so),
depends on whether we want to follow Rani Sharoni's suggestion. If
not, I think we can allow the templated constructor and do a static
assert in its body

     BOOST_STATIC_ASSERT((is_same<remove_cv<T>::type,
remove_cv<U>::type>::value));

The ordinary conversion rules should do the rest.

If we want to implement Rani's suggestion, all I can think of is
something like:

     template<typename U>
     move_ptr( const move_ptr< U[] >& ptr, typename enable_if<
is_more_cv< T, U> >::type* = 0);

Where is_more_cv is defined to mean is_same<remove_cv<T>::type,
remove_cv<U>::type> and U is no more cv-qualified than T.

This is pretty messy. Is there any easier way?

Jonathan


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