To my understanding std::is_move_constructible
returns a true for types that can be moved. But how can you call a move constructor that has never been defined? For example when you compile and run the following code with g++ -std=c++14 -fno-elide-constructors
the move constructor is never called. And in fact it isn't even generated by the compiler, since the class has a user defined copy constructor.
But the following code shows that std::is_move_constructible
returns true for the Something
class. So my question is should std::is_move_constructible
really be called std::is_rvalue_constructible
?
#include <iostream>
#include <type_traits>
using namespace std;
class Something {
public:
Something() {}
Something(const Something&) {
cout << "Something(const Something&)" << endl;
}
};
int main() {
Something something_one{};
auto something_two = Something{std::move(something_one)};
auto something_three = Something{};
(void) something_two;
(void) something_three;
cout << std::is_move_constructible<Something>::value << endl;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire