Is std::array guaranteed to be POD if T is POD?

前端 未结 3 984
终归单人心
终归单人心 2020-12-06 16:27

I\'m currently writing a C++ memory editing library and for the read/write APIs I use type traits (std::is_pod, std::is_same) and boost::enable_if to provide 3 overloads:

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 17:00

    By definition of POD:

    9 Classes

    9 A POD struct is a class that is both a trivial class and a standard-layout class, and has no non-static data members of type non-POD struct, non-POD union (or array of such types). Similarly, a POD union is a union that is both a trivial class and a standard layout class, and has no non-static data members of type non-POD struct, non-POD union (or array of such types). A POD class is a class that is either a POD struct or a POD union.

    [Emphasis mine]

    std::array does satisfy all the requirements of being a trivial, standard-layout class template. So the answer to your question is yes.

提交回复
热议问题