Moving can't be implemented efficiently (O(1)) on std::array, so why does it have move constructor ?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
Have a look at the standard:
23.3.2.2 array constructors, copy, and assignment [array.cons]
The move constructor and assignment operator are by far not free, they may not be provided.
To summarize and expand on other answers,
array<T>
should be moveable (whenT
itself is moveable) because:T
may be efficiently moveable.T
may be move-only.std::array
has a compiler generated move constructor, which allows all the elements of one instance to be moved into another. This is handy if the elements are efficiently moveable or if they are only movable:So I would say
std::array
should have a move copy constructor, specially since it comes for free. Not to have one would require for it to be actively disabled, and I cannot see any benefit in that.