c++ - Should std::array have move constructor? -
moving can't implemented efficiently (o(1)) on std::array, why have move constructor ?
std::array
has compiler generated move constructor, allows elements of 1 instance moved another. handy if elements efficiently moveable or if movable:
#include <array> #include <iostream> struct foo { foo()=default; foo(foo&&) { std::cout << "foo(foo&&)\n"; } foo& operator=(foo&&) { std::cout << "operator=(foo&&)\n"; return *this; } }; int main() { std::array<foo, 10> a; std::array<foo, 10> b = std::move(a); }
so std::array
should have move copy constructor, specially since comes free. not have 1 require actively disabled, , cannot see benefit in that.
Comments
Post a Comment