Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2001-01-07 12:48:07

Howard Hinnant wrote on 1/6/2001 11:37 AM
>I'm up to requiring this in the primary:
> X* ptr_;
> template<class Y> auto_ptr(auto_ptr<Y[]>& a) throw();
> template<class Y> operator auto_ptr<Y[]>() throw();
> template<class Y> auto_ptr& operator=(auto_ptr<Y[]>&) throw();
> template<class Y> operator auto_ptr_ref<Y[]>() throw();

FWIW, I've come up with an alternative to these private declarations for
short circuting conversions between array and single auto_ptr. This
alternative is just as intrusive on the primary, but it may have other
advantages such as creating a more scalable system for this type of
problem in smart pointers in general. At any rate, here it is for

Analogous to the iterator tag types I created two smart pointer tag types:

struct single_ptr_tag {};
struct array_ptr_tag {};

Then the primary and specilization typedef the appropriate tag to

template<class X>
class auto_ptr
     typedef single_ptr_tag category;

template<class X>
class auto_ptr<X[]>
     typedef array_ptr_tag category;

Then the member template converting methods of the primary are laced with
compile-time asserts that test for incompatible tags. For example:

template<class X>
template<class Y>
auto_ptr<X>::auto_ptr(auto_ptr<Y>& a) throw()
        : ptr_(a.release())
auto_ptr<Y>::category>::value> cant_convert;


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