mercredi 14 septembre 2016

Automatic implicit generation of move ctors

Let we have a class with n fields. Each field can be moved. So do we have to explicitly define 2^n constructors?

The example with n=2:

struct A{
 std::vector<B> a;
 std::shared_ptr<B> b;
 A(std::vector<B> &a, std::shared_ptr<B> &b):a(a),b(b){};
 A(std::vector<B> &a, std::shared_ptr<B> &&b):a(a),b(std::move(b)){};
 A(std::vector<B> &&a, std::shared_ptr<B> &b):a(std::move(a)),b(b){};
 A(std::vector<B> &&a, std::shared_ptr<B> &&b):a(std::move(a)),b(std::move(b)){};
};

Aucun commentaire:

Enregistrer un commentaire