samedi 26 mars 2016

std::array aggregate initialization and template integral types

From the documentation of std::array, we find that it can be initialized as it follows (using aggregate initialization):

struct S {
    S(): arr{0,1} { }
    std::array<int,2> arr;
};

Anyway, a problem arises in this case:

template<int N>
struct S {
    S(): arr{/*??*/} { }
    std::array<int,N> arr;
};

How can one initialize the array while constructing s (as an example with values from 0 to N-1 or using a constexpred function to which to pass the indexes)?

Aucun commentaire:

Enregistrer un commentaire