[type traits][enable_if] how do I resolve ambiguous class template instantiation?
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?
TIA
Steve
#include
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
participants (2)
-
Jeremiah Willcock
-
Steve Lorimer