vendredi 8 juin 2018

In a trivially copyable struct shall the move semantics be implemented?

I have such a struct:

template <class T> struct Dimensions
{
    T horizontal{}, vertical{};

    Dimensions() = default;
    Dimensions(const T& horizontal, const T& vertical)
        : horizontal(horizontal), vertical(vertical) {}
    Dimensions(const Dimensions& other) = default;
    Dimensions& operator=(const Dimensions& other) = default;
    Dimensions(Dimensions&& other) = default; // ?
    Dimensions& operator=(Dimensions&& other) = default; // ?
    ~Dimensions() = default;

    // ... + - * / += -= *= areNull() ...

}

which I instantiate like Dimensions<int> or Dimensions<double>. Since it is trivially copyable, what would be the best policy here, generate the move constructor and move assignment operators as = default or avoid the implicit ones by = delete?

Aucun commentaire:

Enregistrer un commentaire