My attempt would look something like this:
template<typename T, typename U> typename std::enable_if< std::is_convertible< U&&, T >::value >::type
the second argument is all that you can convert to T , but we take it using a universal link and conditionally translate it to *dest . I test for convertibility in the signature, and not that the body does not compile, because refusing to search overload seems more polite than refusing to compile the body.
Living example .
Compared to simpler:
template<typename T> void assign( T* dest, typename std::identity<T>::type src ) { *dest = std::move(src); }
the above saves 1 move . If you have an expensive class transfer or a class that is only copied and expensive to copy, this can save a considerable amount.
source share