I’m trying to write a template that behaves one way if T has a move constructor, and another way if T does not. I tried to look for a type trait that could identify this but have had no such luck and my attempts at writing my own type trait for this have failed.
Any help appreciated.
I feel the need to point out a subtle distinction.
While
<type_traits>does providestd::is_move_constructibleandstd::is_move_assignable, those do not exactly detect whether a type has a move constructor (resp. move assignment operator) or not. For instance,std::is_move_constructible<int>::valueistrue, and consider as well the following case:Note that the user-declared copy constructor suppresses the implicit declaration of the move constructor: there is not even a hidden, compiler-generated
copy_only(copy_only&&).The purpose of type traits is to facilitate generic programming, and are thus specified in terms of expressions (for want of concepts).
std::is_move_constructible<T>::valueis asking the question: is e.g.T t = T{};valid? It is not asking (assumingTis a class type here) whether there is aT(T&&)(or any other valid form) move constructor declared.I don’t know what you’re trying to do and I have no reason not to believe that
std::is_move_constructibleisn’t suitable for your purposes however.