I have been developing in c++ for about 6 months. So, by no means am I an expert. I have come across a problem where I need some sort of data structure to hold information in pairs - I think. I'm using Microsoft Visual C++. One of my problems is I have an object that is directly related to 1 other of the same object, but I would only like to show one object of the pair in a GUI. If that object is selected then somehow it triggers the object that is related to it and I remove both from my data strucuture.
Lets say I have 10 distinct objects in my data structure.
Then I would have 5 pairs or 5 objects that are related to another object in the data strucutre.
They are related by date or price.
Can anyone help me with a solution? I'm not sure if I'm making sense, lol.
STL has a "pair" that holds two items that belong together in some fashion.
Not sure if that's much help or not.
Yeah, I can see how that would work. Can I have a std::set<type pair> set1
If you are going to use a std::set<std::pair<T1, T2> >, a std::map<T1, T2> may be appropriate.
If you have a key-value situation, where one type is always the type you use to uniquely identify a pair, then use a map. If a pair is uniquely identified by both types, then you can use a set<pair<T1, T2>, comparator> where comparator is a custom function or object for comparing pair<T1, T2> objects.
So which you choose depends on how you would uniquely identify an object in your container.