Quantcast
Channel: Make a c++ iterator that traverses 2 containers - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by grepsedawk for Make a c++ iterator that traverses 2 containers

$
0
0

I will repost my answer to a similar question. I think this will do what you want.

Use a library like Boost.MultiIndex to do what you want. It scales well and there is a lot less boiler plate code if you want to add new indexes. It is also usually more space and time efficient

typedef multi_index_container<  Container,  indexed_by<    sequenced<>, //gives you a list like interface    ordered_unique<Container, std::string, &Container::a_value>, //gives you a lookup by name like map    ordered_unique<Container, std::string, &Container::b_value> //gives you a lookup by name like map>> container;

If you are iterating over one index, you can switch to another index by using the iterator projection concept in the library.


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>