It is clear that std::array<type,count>
can't store references. However it is possible to write
std::tuple<int &, int &, int &, int &, int &>
and get what you expect. See
#include <array>
#include <tuple>
#include <iostream>
int main(){
int a = 10;
int b = 20;
int c = 20;
// Does not compile
//std::array<int&,3> x = {a,b,c};
using TInt3 = std::tuple<int&,int&,int&>;
TInt3 y = {a,b,c};
std::cout << sizeof(TInt3) << std::endl;
std::get<0>(y)=11;
std::cout << "a " << a << std::endl;
}
where a 11
is output. It is however tedious writing it out long hand. How can I generate a type ( in c++11 )
TupleAllSame<type, count>
so that the following are equivalent
TupleAllSame<int &, 2> <--> std::tuple<int &, int &>
TupleAllSame<double, 4> <--> std::tuple<double, double, double, double>
TupleAllSame<std::string &, 3> <--> std::tuple<std::string &, std::string &, std::string &>