|
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:
>
>private:
> 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
comments:
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
"category":
template<class X>
class auto_ptr
{
public:
typedef single_ptr_tag category;
...
};
template<class X>
class auto_ptr<X[]>
{
public:
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>
inline
auto_ptr<X>::auto_ptr(auto_ptr<Y>& a) throw()
: ptr_(a.release())
{
compile_assert<is_same<auto_ptr<X>::category,
auto_ptr<Y>::category>::value> cant_convert;
}
-Howard
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk