Given a collection of something that is modeled as:
struct Foo { int id; std::string name; };
where id
is unique and name
is non-unique/non-{null|empty}.
How do I use a datastructure like boost::multi_index that will allow me to do the equivalent of:
select id, name from Foo group by name order by id
The standard STL containers aren't getting me to the promised land. I used a sql variant above only to get my point across. I am not really dealing with any databases.
UPDATE:
So, apparently all I need is:
typedef boost::multi_index_container<
Foo,
indexed_by<
ordered_unique<identity<Foo>>,
ordered_unique<member<Foo, std::string, &Foo::name>>
>
> MIC;
Can someone confirm I have got this right? It seems to work. I haven't tested it yet.