Why can't std::tuple be trivially copyable?

后端 未结 2 1006
陌清茗
陌清茗 2020-12-15 10:25

Built with this online compiler, the following code:

#include 
#include 
#include 

int main() {
    std::cou         


        
2条回答
  •  猫巷女王i
    2020-12-15 10:27

    Because std::tuple has copy/move ctor and assignment operators, it makes the class not-trivially-copyable.

    See cpp reference:

    A trivially copyable class is a class that

    Has no non-trivial copy constructors (this also requires no virtual functions or virtual bases)
    Has no non-trivial move constructors
    Has no non-trivial copy assignment operators
    Has no non-trivial move assignment operators
    Has a trivial destructor
    

    But std::tuple has all of the above constructors and assignment operators.

提交回复
热议问题