Using array as tuple member: Valid C++11 tuple declaration?

后端 未结 1 1422
春和景丽
春和景丽 2021-01-19 14:14

The code below compiles fine with G++ 4.7.2:

#include 
std::tuple x;

With clang++ 3.2, however, the follow

相关标签:
1条回答
  • 2021-01-19 15:15

    I don't think there is anything in the Standard that forbids your declaration. However, you will run into problems as soon as you try to initialise, copy, move or assign your tuples, because for these operations, all member types of the tuple must be able to be used as initialisers, copy-constructible, copy-assignable and move-assignable, respectively (§20.4.2.1). None of this is the case for arrays.

    You will be better off using std::array instead of C-style arrays:

    #include <tuple>
    #include <array>
    std::tuple<float,std::array<int,2> > x;
    
    0 讨论(0)
提交回复
热议问题