Using arrays in std::pair to extend the amount of data

I'm trying to extend someone else's code which is using std::queue and std::pair types pretty frequently. For the following code, I need to extend the number of variables in std::pair.second and prefer it to be more flexible for number of variables like an array (for future modification).

someClass->myQueue.push(std::pair<T1,uint64_t>(var1, var2));

So I tried to do something like:

someClass->myQueue.push(std::pair<T1,uint64_t[N]>(var1,{e1,e2,...,eN}));

After modifying the related definitions etc. in the code I got following error and warning, which I don't understand anything from. However it sounds like that this is not the appropriate way to do this kind of modification.

myArray = myQueue.front().second; 
        ^
error: invalid array assignment
...
someClass->myQueue.push(std::pair<T1,uint64_t[N]>(var1,{e1,e2,...,eN}));
                                                                    ^
warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]

I saw tuple and recursive usage of std::pair as solutions on web, but I want to make minimum change on the code since several classes will be effected by this. What is the proper way to do it?

Thanks

Upvotes: 0

Views: 120

Answers (1)

Barry
Barry

Reputation: 302748

Raw C++ arrays are not copy-assignable. That's the error you're getting. Instead, you should use an array type that is copy-assignable: std::array. Specifically in this case:

std::pair<T1, std::array<uint64_t, N>>

Upvotes: 5

Related Questions