Should std::array have move constructor?

前端 未结 3 2002
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-18 20:33

Moving can\'t be implemented efficiently (O(1)) on std::array, so why does it have move constructor ?

3条回答
  •  生来不讨喜
    2021-02-18 21:38

    Have a look at the standard:

    23.3.2.2 array constructors, copy, and assignment [array.cons]

    The conditions for an aggregate (8.5.1) shall be met. Class array relies on the implicitly-declared special member functions (12.1, 12.4, and 12.8) to conform to the container requirements table in 23.2. In addition to the requirements specified in the container requirements table, the implicit move constructor and move assignment operator for array require that T be MoveConstructible or MoveAssignable, respectively.

    The move constructor and assignment operator are by far not free, they may not be provided.

提交回复
热议问题