Question

I'm trying to use Boost's multi-index container for fast look up, but I'm having a hard time with the find. I find some of the documentation a little confusing. Here is what I have:

struct reports_entry
{
  reports_entry(  const std::string& category,
               const std::string& reportName):
               cat_name_(category),
               report_name_(reportName)
  {}
  std::string cat_name_;
  std::string report_name_;
};

typedef multi_index_container<
 reports_entry, indexed_by<
   ordered_non_unique<member<reports_entry, std::string
    , &reports_entry::cat_name_> >
    , ordered_unique<member<reports_entry, std::string
   , &reports_entry::report_name_> >
  >
 > reports_set;

fnv.insert(reports_entry("report", "somekindofreport1.dat"));
fnv.insert(reports_entry("report", "somekindofreport3.dat"));
fnv.insert(reports_entry("report", "somekindofreport2.dat"));
fnv.insert(reports_entry("mysecondreport", "somekindofreport4.dat"));
fnv.insert(reports_entry("mysecondreport", "somekindofreport5.dat"));

So now if I try to search for all the dumbmreport reports I seg fault:

Rname_view::iterator it = fdv.find("report");
std::cout << it->report_name_;

Am I doing this right? Do I need a loop to get all the reports of that type? Or am I totally misusing this?

Thanks

Was it helpful?

Solution

I think you're using an index sorted by report name to look for a category name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top