In general you can store std::pair<T&,int>
in an std::vector
, but you have to insert values correctly.
make_pair(x, 0)
creates a std::pair<T,int>
with no reference.
You can for example use an initializer lists instead:
v.push_back({x,0});
Another method would be using std::ref
:
v.push_back(std::make_pair(std::ref(x),0));
Example:
std::vector<std::pair<int&,int>> v;
int a = 1;
v.push_back({a,a});
v.push_back(std::make_pair(std::ref(a),a));
a = 2;
std::cout << v[0].first << " " << v[0].second << std::endl; // will write "2 1"
However for your purpose it will not work. You should not get references to keys of a std::map
. A std::map
is a sorted container, you can not just change a key from the outside. This would mess up the inner workings of the std::map
.