I have a class Input, which has default move/copy constructors.
Input(const Input &) = default;
Input(Input &&) = default;
The following assertions fail however.
static_assert(std::is_copy_constructible<Input>(), "Input is not copy-constructible");
static_assert(std::is_move_constructible<Input>(), "Input is not move-constructible");
Why is that?
Here is a full example:
#include <type_traits>
class A {
public:
A(const A &) = default;
static_assert(std::is_copy_constructible<A>(), "");
};
int main() {
// your code goes here
return 0;
}
Your problem is that the
static_assert
is in the class declaration. The compiler can't know for sure when it reaches thestatic_assert
whether the class is copy- or move-constructible, because the class hasn't been fully defined yet.