Boost logo

Boost Users :

Subject: Re: [Boost-users] [type traits][enable_if] how do I resolve ambiguous class template instantiation?
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2010-07-28 13:26:29

On Wed, 28 Jul 2010, Steve Lorimer wrote:

> I'm trying to use template specialization and enable_if / type_traits to correctly allocate memory for different types, where the template parameter will be
> one of:
> 1. boost::intrusive_ptr<U> // create U on the heap, return intrusive_ptr
> 2. boost::shared_ptr<U>    // create U on the heap, return shared_ptr
> 3. U*                      // create U on the heap, return raw pointer 
> 4. U                       // create U on the stack
> I'm pretty sure I'm just doing something stupid, but I'm getting ambiguous conflicts between my template for types of U and the smart pointer types. 
> Please can you comment on how to fix the code below?

Does this require enable_if? Unless you have objects that inherit from
intrusive_ptr or shared_ptr that you want to catch, something like:

template <typename T> struct alloc { /* stack */ };
template <typename T> struct alloc<T*> { /* raw pointer */ };
template <typename T> struct alloc<shared_ptr<T> > { /* shared_ptr */ };
template <typename T> struct alloc<intrusive_ptr<T> > { /* intrusive_ptr */ };

is likely to be enough. Or are you going to expand to more cases later
than cannot be handled by simple specializations?

-- Jeremiah Willcock

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at