Jump to content
  • Advertisement
Sign in to follow this  
DumitruSorin

multi_index_container

This topic is 3988 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I hava defined my container like this:
	struct name{};
	typedef multi_index_container<
	  shared_ptr<Texture2D>,
	  indexed_by<
	    hashed_unique<
	    	tag<name>,
	    	BOOST_MULTI_INDEX_CONST_MEM_FUN( Texture2D ,std::string, getName)
	    >
	  >
	> TextureContainer;

the problem is that the tutorial and the examples that the boost library provides havn't answerd how would i go about deleting a shared_ptr from the container and what would be the best way of searching and retrieving a shared_ptr from the container.

Share this post


Link to post
Share on other sites
Advertisement
Central to the concept of the multi-index container is that of 'views'.

You search by getting a certain view into the container, so in this case you'd do the following;


TextureContainer myTextures;
typedef TextureContainer::index<name>::type textureByName;

textureByName &name_idx = myTextures.get<name>();
textureByName::iterator it = name_idx.find("sometexture.jpg");

if(it != name_idx.end())
{
// we have a texture!
}



Based on what you have however I'm left to ask why a MI-Container, why not a map of some sort? (the Boost svn has a hashmap in it now iirc)

Share this post


Link to post
Share on other sites
at first it was a hashmap. but i thought that a hashtable would be faster.
Google said that i could implement a hashtable using a multi_index_container so i thought i should try it to see how it works

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!