I want to develop a small polymorphic class with type erasure and I wonder which version of the templatized constructor is better and should be used.
We can pass by value:
class A
{
...
template< typename T >
A( T t ) { /* create the underlying model via std::move */ }
...
};
or we can use a universal reference:
class A
{
...
template< typename T >
A( T &&t ) { /* create the underlying model via std::forward */ }
...
};
(The universal reference has to be enabled if for the case that T
is not the class itself and the class is not copied). Any ideas? Both version look equal to me.