Also, map might be more appropriate:
typedef map<int, string> FileMap;FileMap textures;for (/*each texture*/){ textures.insert (FileMap::value_type (textureID, textureFileName));}// when looking for textures: FileMap::iterator texIt = textures.find (textureID); if (texIt != textures.end ()) { cout << "Texture found: id = " << texIt->first << ", filename = " << texIt->second.c_str () << endl; } else { cout << "Texture id " << textureID << " not found" << endl; }}
This solution assumes that no two textures have the same ID (although two different IDs are free to have the same filename).
The difference between a map and a list is:
1) The map splits up each record between data and key, where key is what you use to search the container. Since it seems to me that your structure is really just a key/data structure, map seemed more appropriate.
2) Finding a record in a list takes linear time. Finding a record in a map takes logarithmic time.
3) Lists can be in any order. A map is always sorted by key. Since it''s sorted, the type of key you use in a map must have a compare function, but if you use a standard type or one that already has a valid less-than operator, you don''t need to do any extra work.
4) Lists can have duplicate records. Maps cannot have two records with the same key (although multimap can).
5) Lists can be combined or split in constant time (really fast). Maps have to have each element read-out and inserted into a new map (really slow).
Depending on your needs, different containers are appropriate at different times. Looks to me like a map is more appropriate for your situation above.
Also, if you only build your table of texture IDs at the beginning of the program and never change it afterward, you can just use a vector and have REALLY fast searches. You can even abandon an STL container completely, and just have an array of your texture structs. When you want to search it, use lower_bound and pass it a predicate that understands your structure. This give you a binary search with no tree overhead, which is the fasting thing out there (besides hash tables, for which there is no C++ standard container
).