I have a large group of objects (potentially 1000) that I need to store in a container. I need to find specific instances in two ways: either by its identification number (64-bit unsigned int), or by name (std :: string). Usually by ID it will be the most common, but in some cases the name is known, but not the identifier.
std :: map can provide one ↔ value, however I'm not sure that there are two sets of std :: map containers here, one for identifiers and another for strings.
EDIT - REVISED code and error:
Well, I decided that I would give the multi-index a try, since I have an incentive anyway, but I seem to be unable to compile it, although I did it in the same way as in the documentation, as far as possible I can say: (
test code:
namespace common
{
class MyBaseClass
{
public:
typedef boost::uint64_t Id;
const std::string &getName()const{return name;}
Id getId()const{return id;}
...other stuff...
};
}
class MyClass : public common::MyBaseClass
{
...other stuff...
};
typedef boost::multi_index_container
<
MyClass*,
boost::indexed_by
<
boost::ordered_unique<boost::const_mem_fun<MyBaseClass, MyBaseClass::Id, &MyBaseClass::getId > >,
boost::ordered_unique<boost::const_mem_fun<MyBaseClass, const std::string&, &MyBaseClass::getName> >
>
>MyClassList;
and your average boost pattern error ...
c:\lib\++\boost\boost\aligned_storage.hpp(69): C2872: 'detail':
"boost:: detail"
"boost:: multi_index:: detail"
c:\lib\++\boost\boost\multi_index\detail\index_node_base.hpp(42): . "boost:: aligned_storage",
[
size_ = 4,
alignment_ = 4
]
c:\lib\++\boost\boost\multi_index\detail\index_node_base.hpp(47): . "boost:: multi_index:: detail:: pod_value_holder",
[
= MyClass *
]
c:\lib\++\boost\boost\multi_index\detail\ord_index_node.hpp(582): . "boost:: multi_index:: detail:: index_node_base",
[
= MyClass *,
= ::
]
c:\lib\++\boost\boost\multi_index\ordered_index.hpp(137): . "boost:: multi_index:: detail:: ordered_index_node",
[
= :: multi_index:: :: index_node_base >
]
c:\lib\++\boost\boost\multi_index\ordered_index.hpp(119): . "boost:: multi_index:: detail:: ordered_index",
[
KeyFromValue = :: multi_index:: const_mem_fun,
= :: , :: → ,
SuperMeta = boost:: multi_index:: detail:: nth_layer < 2, MyClass *, boost:: multi_index:: indexed_by > , boost:: multi_index:: ordered_unique → , std:: allocator > ,
TagList = :: MPL:: vector0,
= :: multi_index:: :: ordered_unique_tag
]
c:\lib\++\boost\boost\multi_index_container.hpp(86): . "boost:: multi_index:: detail:: ordered_index",
[
KeyFromValue = :: multi_index:: const_mem_fun,
= :: ,
SuperMeta = boost:: multi_index:: detail:: nth_layer < 1, MyClass *, boost:: multi_index:: indexed_by > , boost:: multi_index:: ordered_unique → , std:: allocator > ,
TagList = :: MPL:: vector0,
= :: multi_index:: :: ordered_unique_tag
]
c:\projects\bad_angle_studios\brak3\trunk\source\source\server\MyClass.cpp(18): . "boost:: multi_index:: multi_index_container",
[
= MyClass *,
IndexSpecifierList = :: multi_index:: indexed_by > , :: multi_index:: ordered_unique →
]
c:\lib\++\boost\boost\aligned_storage.hpp(53): C2872: 'detail':
"boost:: detail"
"boost:: multi_index:: detail"
c:\lib\++\boost\boost\aligned_storage.hpp(56): . boost:: detail:: aligned_storage:: aligned_storage_imp:: data_t '
[
size_ = 4,
alignment_ = 4
]
c:\lib\++\boost\boost\aligned_storage.hpp(69): . "boost:: detail:: aligned_storage:: aligned_storage_imp",
[
size_ = 4,
alignment_ = 4
]
c:\lib\++\boost\boost\aligned_storage.hpp(73): C2872: 'detail':
"boost:: detail"
"boost:: multi_index:: detail"
c:\projects\bad_angle_studios\brak3\trunk\source\source\server\MyClass.cpp(44): C2676: binary '[': 'MyClassList' ,