Using an array as a tuple element: Valid C ++ 11 tuple declaration?

The code below compiles with g ++ 4.7.2:

#include <tuple>
std::tuple<float,int[2]> x;

      

With clang ++ 3.2, however, the following error occurs:

error: array initializer must be an initializer list.

If I remove the type float

from the tuple declaration, the error goes away. Is the above tuple formulation valid?

($ CXX -std = C ++ 11 -c file.cpp)

+3


source to share


1 answer


I don't think there is anything in the Standard that prohibits your declaration. However, you run into problems as soon as you try to initialize, copy, move, or assign your tuples, because for these operations, all types of tuple members must be able to be used as initializers, copyable, and carry over accordingly (§20.4 .2.1). This does not apply to arrays.

You're better off using std::array

C style arrays instead:



#include <tuple>
#include <array>
std::tuple<float,std::array<int,2> > x;

      

+2


source







All Articles