|
Boost : |
From: Howard Hinnant (hinnant_at_[hidden])
Date: 2004-01-23 18:39:40
On Jan 23, 2004, at 6:02 PM, Jonathan Turkanis wrote:
> 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?
I think Rani's suggestion is the best way to go. Maybe something like
(untested):
template <class T, class U>
struct is_array_convertible
{
private:
typedef typename remove_bounds<T>::type t_element;
typedef typename remove_bounds<U>::type u_element;
typedef typename remove_cv< t_element >::type t_basic;
typedef typename remove_cv< u_element >::type u_basic;
public:
static const bool value =
is_array<T>::value &&
is_array<U>::value &&
is_same<t_basic, u_basic>::value &&
is_convertible<t_element*, u_element*>::value;
};
...
template<typename U>
move_ptr(
const move_ptr< U >& ptr,
typename enable_if
<
is_array_convertible<U, T[]>::value
>::type* = 0);
You might see messy. I see: Wow, that's really cool! ;-)
Also, nice job on picking up this cv issue for arrays. I hadn't
thought about it.
As long as we're on the subject, make sure you restrict move_ptr<U[]>
conversions to move_ptr<T>, even if is_convertible<U*, T*>:
move_ptr<int> p(move_ptr<int[]>()); // should not compile
-Howard
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk