A common design problem I run into, is that I bundle two variables together and then lose the ability to reference them in a meaningful way.
std::pair<int,int> cords;
cord.first = 0; //is .first the x or y coordinate?
cord.second = 0; //is .second the x or y coordinate?
I've considered writing basic structs instead, but then I lose a lot of the benefits that come along with std::pair
:
- make_pair
- non-member overloaded operators
- swap
- get
- etc.
Is there a way to rename or provide an alternative identifier for the first
and second
data members?
I was hoping to leverage all of the the functions that accept std::pair
,
but still be able to use them in the following way:
std::pair<int,int> cords;
//special magic to get an alternative name of access for each data member.
//.first and .second each have an alternative name.
cords.x = 1;
assert(cords.x == cords.first);