The documentation for Boost multiindex containers seem to indicate that I can use it as a set after declaring an index to iterate over. So I was wondering if it is possible to hide the boost implementation and return an iterator masqueraded as an iterator to an std::set
Ex: Header
typedef multi_index_container<
Employee,
indexed_by<
ordered_non_unique<
composite_key<
Employee,
member<Employee, int, &Employee::id>,
member<Employee, int, &Employee::salary>
>
>
> > EmployeeSet;
const std::set<Employee>::iterator getEmployees();
static EmployeeSet employeeSet;
Test.cc:
const std::set<Test::Employee>::iterator getEmployees(){
std::pair<EmployeeSet::iterator, EmployeeSet::iterator> by_id =
employeeSet.equal_range(id);
return by_id.first;
}
Is it possible to do something like this? and How?
No, you can't. The EmployeeSet
you have defined works like a std::set
(a std::multiset
, actually), but it is not one. The iterator
types of these unrelated containers are different and you can't pass one as the other.
Maybe you can reconsider why you need to pass an iterator
to an index of a multi_index_container
as a std::set::iterator
.