definition of a container.

closed account (SECMoG1T)
just looking for ideas.

define a container such that:
-each element in it is an std::pair<T1,T2> where T1 might be same as T2 or might differ.
- each item in the pair acts as a key to its paired item such that you can
use4 either to retrive its partner.
- each key can only occur once.

would it be overly complex?
Last edited on
closed account (E0p9LyTq)
You'd do better looking at associative containers, like std::map, std::set or the variant types, IMO.

std::pair and std::tuple could be considered C++ templated versions of C structs.
closed account (SECMoG1T)
nice suggestion @furryGuy ,std::map, std::set,std::multi*** ... are good and actually thw only ones providing associative props{key:value} but for now i'd love to put them aside and only return to them if i fail to develop an alternative that would provide the specs above.

can you think of another way that could be achieved?

NB: this "std::pair<T1,T2>" is not strictly required anything that can pair values of similar or
different types would be desirable.

being able to provide the second functionality would be a life saver.


thank you very much.
Is it necessary to support more than one unique key/value pair?
In particular, what's wrong with boost::bimap?
https://www.boost.org/doc/libs/1_68_0/libs/bimap/doc/html/boost_bimap/one_minute_tutorial.html
closed account (E0p9LyTq)
@mbozzi, I didn't know about Boost's bimap. Thanks for the link. :)
closed account (SECMoG1T)
guys boost::bimap should be part of std:: ,killed all the birds with one stone. thanks @Mbozzi
Topic archived. No new replies allowed.