How can I check if a move constructor is being generated implicitly?
Declare the special member functions you want to exist in MyStruct
, but don't default the ones you want to check. Suppose you care about the move functions and also want to make sure that the move constructor is noexcept
:
struct MyStruct {
MyStruct() = default;
MyStruct(const MyStruct&) = default;
MyStruct(MyStruct&&) noexcept; // no = default; here
MyStruct& operator=(const MyStruct&) = default;
MyStruct& operator=(MyStruct&&); // or here
};
Then explicitly default them, outside the class definition:
inline MyStruct::MyStruct(MyStruct&&) noexcept = default;
inline MyStruct& MyStruct::operator=(MyStruct&&) = default;
This triggers a compile-time error if the defaulted function would be implicitly defined as deleted.
As Yakk pointed out, it's often not relevant if it's compiler generated or not.
You can check if a type is trivial or nothrow move constructable
template< class T >
struct is_trivially_move_constructible;
template< class T >
struct is_nothrow_move_constructible;
http://en.cppreference.com/w/cpp/types/is_move_constructible
Limitation; it also permits trivial/nothrow copy construction.