I'd like to detect (and use the result in std::enable_if
) whether a C++ class has a move constructor defined.
The following program prints MOVE
, so using std::is_move_constructible
is not the way to do it:
#include <stdio.h>
#include <type_traits>
class C {
public:
C() { puts("C()"); }
C(int) { puts("C(int)"); }
~C() { puts("~C()"); }
C(const C&) { puts("C(const C&)"); }
// C(C&&) { puts("C(C&&)"); }
C& operator=(const C&) { puts("C="); return *this; }
};
int main(int argc, char** argv) {
(void)argc; (void)argv;
if (std::is_move_constructible<C>::value) puts("MOVE");
return 0;
}
I need a program which prints MOVE
only if I uncomment the line containing the &&
.
Aucun commentaire:
Enregistrer un commentaire