From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-08-22 21:37:22
"Alex Chovanec" <achovane_at_[hidden]> wrote in message
> Ok, so I have a class Ptr_Wrapper that is a wrapper around a pointer
> object of arbitrary type,
You mean Ptr_Wrapper is not a template? How does it remember the type
of object it contains?
> and it has a template constructor which accepts
> any kind of iterator. The constructor initializes the pointer member
> the address of the object that the iterator refers to.
> Now, I don't want is_convertible<T, Ptr_Wrapper> to be true for any
> so I want to use the enable_if library to eliminate specializations
> template constructor where the type passed in is not a Readable
> iterator with the correct pointer type. But again, I can't just use
> is_readable_iterator<T> and is_lvalue_iterator<T>, because either
> cause a compile error if T is not an iterator.
> I don't want there to be a compile error in this case, because
> has another constructor which accepts a reference to an object an
> initializes the pointer member from that.
Possibly dumb question: why not have this second overload take a
> I want this constructor to be
> chosen if a reference is passed instead of an iterator.
> Thus, in the template metaprogram that I use to decide whether or
> include a particular template specialization of the constructor in
> of candidate functions, I need to check that T is some kind of
> before applying is_readable_iterator<T> and is_lvalue_iterator<T>.
> Otherwise, I may get an unwanted compile error.
Okay, assuming the second overload has to take a reference, this does
sound like a case where you want to be able to treat almost any
possible type. Realistically, how often would:
Ptr_Wrapper( const T&,
typename enable_if< is_incrementable<T> >::type* =
typename enable_if< is_dereferenceable<T> >::type*
= 0 );
typename disable_if< is_incrementable<T> >::type* =
typename disable_if< is_dereferenceable<T>
>::type* = 0 );
select the wrong overload?
If it's fairly rare, you could add a disambiguation mechanism:
Ptr_Wrapper pw = Ptr_Wrapper::from_object(x);
Ptr_Wrapper pw( disambiguation_func_with_better_name(x) );
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk