0

Starting with this snippet:

#include <string>
#include <tuple>

class wrap {
   public:
    std::array<std::string, 3> a;
    wrap(std::array<std::string, 3>&& input) : a(std::move(input)){};
};

I read on several sources that an std::array has no move constructor which would make no sense, yet syntax above implies that its not the std::array that is moved but its element. I couldn't found a word about that in cppreference (for instance) and finally stumbled on this post.

It basically says that:

In exactly the same way as any other aggregate. Its implicit move-constructor will move-construct all its members, including the elements of any member arrays.

What would be the standard reference? The best I found is n2904 Defining default copy and move and Move constructors and std::array, regarding std::array only.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Oersted
  • 769
  • 16
  • 2
    https://timsong-cpp.github.io/cppwp/class.copy.ctor#14 – NathanOliver Jun 19 '23 at 15:27
  • 1
    From cpp reference: [`std::array`](https://en.cppreference.com/w/cpp/container/array) (constructor implicitly declared) and [Implicitly-defined_move_constructor](https://en.cppreference.com/w/cpp/language/move_constructor#Implicitly-defined_move_constructor). – Jarod42 Jun 19 '23 at 15:32
  • @Jarod42 OK _For non-union class types (class and struct), the move constructor performs full member-wise move of the object's bases and non-static members, in their initialization order, using direct initialization with an xvalue argument._ – Oersted Jun 19 '23 at 15:36
  • question answered. Thanks – Oersted Jun 19 '23 at 15:37

0 Answers0