Note that there are some explanatory texts on larger screens.

plurals
  1. POAssociative array with multiple keys types, possible?
    primarykey
    data
    text
    <p>Ive got a large bunch of objects (potentially 1000's) which I need to store in a container. I need to be able to find specific instances in two ways, either by its ID number (64bit unsigned int), or its name (std::string). Generally by ID will be the most common, however in some cases the name is known, but not the ID.</p> <p>std::map can provide a single &lt;-> value, however I'm not sure if having 2 sets of std::map containers, one for the Ids and another for the strings is the best approach here.</p> <p>EDIT - REVISED code and error:</p> <p>Ok, I figured i'd give the multi index a try since I have boost anyways, however I can't seem to get it to compile even though I've done it exactly the same as in the documentation as far as I can tell :(</p> <p>test code:</p> <pre><code>namespace common { class MyBaseClass { public: typedef boost::uint64_t Id; //name and id are constant, at least for the period im intrested in //when I want it in the container... const std::string &amp;getName()const{return name;} Id getId()const{return id;} ...other stuff... }; } class MyClass : public common::MyBaseClass { ...other stuff... }; typedef boost::multi_index_container &lt; MyClass*, boost::indexed_by &lt; boost::ordered_unique&lt;boost::const_mem_fun&lt;MyBaseClass, MyBaseClass::Id, &amp;MyBaseClass::getId &gt; &gt;, boost::ordered_unique&lt;boost::const_mem_fun&lt;MyBaseClass, const std::string&amp;, &amp;MyBaseClass::getName&gt; &gt; &gt; &gt;MyClassList; </code></pre> <p>and your average boost template error...</p> <blockquote> <p>c:\lib\c++\boost\boost\aligned_storage.hpp(69) : error C2872: 'detail' : ambiguous symbol<br> could be 'boost::detail'<br> or 'boost::multi_index::detail'<br> c:\lib\c++\boost\boost\multi_index\detail\index_node_base.hpp(42) : see reference to class template instantiation 'boost::aligned_storage' being compiled<br> with<br> [<br> size_=4,<br> alignment_=4<br> ]<br> c:\lib\c++\boost\boost\multi_index\detail\index_node_base.hpp(47) : see reference to class template instantiation 'boost::multi_index::detail::pod_value_holder' being compiled<br> with<br> [<br> Value=MyClass *<br> ]<br> c:\lib\c++\boost\boost\multi_index\detail\ord_index_node.hpp(582) : see reference to class template instantiation 'boost::multi_index::detail::index_node_base' being compiled<br> with<br> [<br> Value=MyClass *,<br> Allocator=std::allocator<br> ]<br> c:\lib\c++\boost\boost\multi_index\ordered_index.hpp(137) : see reference to class template instantiation 'boost::multi_index::detail::ordered_index_node' being compiled<br> with<br> [<br> Super=boost::multi_index::detail::index_node_base><br> ]<br> c:\lib\c++\boost\boost\multi_index\ordered_index.hpp(119) : see reference to class template instantiation 'boost::multi_index::detail::ordered_index' being compiled<br> with<br> [<br> KeyFromValue=boost::multi_index::const_mem_fun,<br> Compare=std::less,std::allocator>>,<br> SuperMeta=boost::multi_index::detail::nth_layer&lt;2,MyClass *,boost::multi_index::indexed_by>,boost::multi_index::ordered_unique>>,std::allocator>,<br> TagList=boost::mpl::vector0,<br> Category=boost::multi_index::detail::ordered_unique_tag<br> ]<br> c:\lib\c++\boost\boost\multi_index_container.hpp(86) : see reference to class template instantiation 'boost::multi_index::detail::ordered_index' being compiled<br> with<br> [<br> KeyFromValue=boost::multi_index::const_mem_fun,<br> Compare=std::less,<br> SuperMeta=boost::multi_index::detail::nth_layer&lt;1,MyClass *,boost::multi_index::indexed_by>,boost::multi_index::ordered_unique>>,std::allocator>,<br> TagList=boost::mpl::vector0,<br> Category=boost::multi_index::detail::ordered_unique_tag<br> ]<br> c:\projects\bad_angle_studios\brak3\trunk\source\source\server\MyClass.cpp(18) : see reference to class template instantiation 'boost::multi_index::multi_index_container' being compiled<br> with<br> [<br> Value=MyClass *,<br> IndexSpecifierList=boost::multi_index::indexed_by>,boost::multi_index::ordered_unique>><br> ]<br> c:\lib\c++\boost\boost\aligned_storage.hpp(53) : error C2872: 'detail' : ambiguous symbol<br> could be 'boost::detail'<br> or 'boost::multi_index::detail'<br> c:\lib\c++\boost\boost\aligned_storage.hpp(56) : see reference to class template instantiation 'boost::detail::aligned_storage::aligned_storage_imp::data_t' being compiled<br> with<br> [<br> size_=4,<br> alignment_=4<br> ]<br> c:\lib\c++\boost\boost\aligned_storage.hpp(69) : see reference to class template instantiation 'boost::detail::aligned_storage::aligned_storage_imp' being compiled<br> with<br> [<br> size_=4,<br> alignment_=4<br> ]<br> c:\lib\c++\boost\boost\aligned_storage.hpp(73) : error C2872: 'detail' : ambiguous symbol<br> could be 'boost::detail'<br> or 'boost::multi_index::detail'<br> c:\projects\bad_angle_studios\brak3\trunk\source\source\server\MyClass.cpp(44) : error C2676: binary '[' : 'MyClassList' does not define this operator or a conversion to a type acceptable to the predefined operator</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload