G
Gianni Mariani
I'm developing a factory template that supports placement new and one of
the methods I need to provide is a copy constructor. The question is,
how do I make the template generic for implementations that may not
support the copy constructor.
It would be very interesting to be able to write:
template <typename T, bool>
struct copy_constructor
{
virtual T * creator( T& v )
{
throw "No copy constructor";
}
};
template <typename T>
struct copy_constructor<T, true>
{
virtual T * creator( T& v )
{
return new T( v );
}
};
template <typename T>
struct factory : copy_constructor<T,is_copy_constructible<T> >
{
virtual T * creator()
{
return new T;
}
};
I'm not even sure it's the right way to do this yet. It's more a
question of "can it be done". I looked at boost::type_traits.hpp
without finding anything suitable.
ideas ?
the methods I need to provide is a copy constructor. The question is,
how do I make the template generic for implementations that may not
support the copy constructor.
It would be very interesting to be able to write:
template <typename T, bool>
struct copy_constructor
{
virtual T * creator( T& v )
{
throw "No copy constructor";
}
};
template <typename T>
struct copy_constructor<T, true>
{
virtual T * creator( T& v )
{
return new T( v );
}
};
template <typename T>
struct factory : copy_constructor<T,is_copy_constructible<T> >
{
virtual T * creator()
{
return new T;
}
};
I'm not even sure it's the right way to do this yet. It's more a
question of "can it be done". I looked at boost::type_traits.hpp
without finding anything suitable.
ideas ?