So once an std::pair
with at least one reference variable has been initialized, for example like this:
int a = 53;
int b = 42;
std::pair<int, int&> foo(33, a);
Is there a way to change where the reference variable is pointing?
Assignment:
foo = std::make_pair(33, std::ref(b));
and swapping:
std::pair<int, int&> bar(33, b);
foo.swap(bar);
appear to just move the new contents to a
and leave second member of foo
pointing where it was before (a
), therefore not doing what I'm trying to achieve here. I am aware that references cannot be rebound as
answered here, but this isn't what I am trying to do here. What I'm trying to do is make a new pair and assign its contents to an existing one which technically isn't the same thing.
Thanks in advance!