I'm trying to retrieve a value from a boost::multi_index_container
, using a unique numerical id index. I've never used boost::multi_index_container
before so I have some trouble understanding how they work. They seem to work a bit like a database, all I want to do is to retrieve an item by specifying the id. Any help would be greatly appreciated.
This is the datatype:
typedef boost::multi_index_container<
// Multi index container holds pointers to the subnets.
Subnet6Ptr,
// The following holds all indexes.
boost::multi_index::indexed_by<
// First is the random access index allowing for accessing
// objects just like we'd do with a vector.
boost::multi_index::random_access<
boost::multi_index::tag<SubnetRandomAccessIndexTag>
>,
// Second index allows for searching using subnet identifier.
boost::multi_index::ordered_unique<
boost::multi_index::tag<SubnetSubnetIdIndexTag>,
boost::multi_index::const_mem_fun<Subnet, SubnetID, &Subnet::getID>
>,
// Third index allows for searching using an output from toText function.
boost::multi_index::ordered_unique<
boost::multi_index::tag<SubnetPrefixIndexTag>,
boost::multi_index::const_mem_fun<Subnet, std::string, &Subnet::toText>
>
>
> Subnet6Collection;
The Subnet6Collection
object is created when a dhcpv6-server (KEA) loads its config file. This file contains an optional numerical id value for each subnet, SubnetID
in the datatype.
I would like to retrieve a Subnet6Ptr
by specifying SubnetID
.