Skip to main content
GameDev.net gamedev.net
🔒 Locked

multi_index_container

Started by DumitruSorin Jan 12, 2008 at 12:42 PM 1 replies 1.8k views
Original Post
DumitruSorin
DumitruSorin
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.
_the_phantom_
_the_phantom_
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)
DumitruSorin
DumitruSorin
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.