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
?
generate the move constructor and move assignment operators as
= default
or avoid the implicit ones by= delete
?
The former, unless you want any code that attempts to std::move
your type to fail compilation. E.g.
template <typename T>
void foo()
{
T a;
T b = std::move(a);
}
struct X
{
X() = default;
X(X&&) = delete;
};
int main() { foo<X>(); }
live example on wandbox.org
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With