If I understand the question you're asking for associative containers. And here's what I dug up from MSDN:
6. Associative Containers
Associative containers store and retrieve their objects according to an association with each other. In other words, the data is stored and retrieved in a sorted order. Therefore, associative containers rely heavily upon comparison operators. There are four different associative containers defined in the STL. They are: set, multiset, map and multimap.
6.1 Set and Multiset
Code:
#include <set>
set<TYPE, PREDICATE, ALLOCATOR>
A set is optimized for fast associative lookup. For lookup purposes, objects are matched using operator==. Objects are ordered within the set according to the user-defined comparator object (the second template argument). The comparator object is typically "less<TYPE>", which causes the data to be sorted in ascending order. Each object in a set has a unique value, as duplicate objects are not allowed. A multiset is similar to a set, except that a multiset can contain objects with duplicate values.
The following function declares a set of ints, fills it with 10 random values, then prints them:
Code:
typedef set<int, less<int>, allocator<int> > INTSET;
void somefunct()
{
INTSET mySet; // declare a set of ints
INTSET::iterator mySetPtr; // and an iterator for the set
int tmpVal;
srand(13); // seed the rand function
// fill the set with 10 random ints - print them as they are added.
for(int i = 0; i < 9; i++){
tmpVal = rand();
cout << tmpVal << ", ";
mySet.insert(tmpVal);
}
cout << endl;
// print the contents of the set (note the values are sorted)
for(mySetPtr = mySet.begin(); mySetPtr != mySet.end();
mySetPtr++)
cout << *mySetPtr << ", ";
cout << endl;
}
Output of somefunct:
81, 16376, 24096, 20348, 11872, 30076, 16059, 26999, 28493,
81, 11872, 16059, 16376, 20348, 24096, 26999, 28493, 30076,
See APPENDIX B for the set and multiset class definitions.
See APPENDIX C for a table of set and multiset methods.
See APPENDIX D for an explanation of the allocator class (third template parameter above).
6.2 Map and Multimap
Code:
#include <map>
map<KEY, TYPE, PREDICATE, ALLOCATOR>
A map holds a set of ordered key/value pairs. The pairs are ordered by key, based upon the user-defined comparator object (3rd template parameter). A map defines a one-to-one relationship, allowing only one value to be associated with a particular key; a multimap defines a one-to-many relationship, allowing many values to be associated with a particular key.
The following declares a map of ints to strings, fills it with 10 key/value pairs and prints them:
Code:
typedef map<int, string, less<int>, allocator<string> > INT2STRING;
void somefunct()
{
INT2STRING myMap;
INT2STRING::iterator i2sPtr;
// Fill myMap with the digits 9 - 0 in reverse order,
// each mapped to its character string counterpart
myMap.insert(INT2STRING::value_type(9,"Nine"));
myMap.insert(INT2STRING::value_type(8,"Eight"));
myMap.insert(INT2STRING::value_type(7,"Seven"));
myMap.insert(INT2STRING::value_type(6,"Six"));
myMap.insert(INT2STRING::value_type(5,"Five"));
myMap.insert(INT2STRING::value_type(4,"Four"));
myMap.insert(INT2STRING::value_type(3,"Three"));
myMap.insert(INT2STRING::value_type(2,"Two"));
myMap.insert(INT2STRING::value_type(1,"One"));
myMap.insert(INT2STRING::value_type(0,"Zero"));
// Now print the pairs - note they are now sorted
// into ascending order...
for(i2sPtr = myMap.begin(); i2sPtr != myMap.end(); i2sPtr++)
cout << "(" << (*i2sPtr).first << ", "
<< (*i2sPtr).second << “)” << endl;
}
Output of somefunct:
(0, Zero)
(1, One)
(2, Two)
(3, Three)
(4, Four)
(5, Five)
(6, Six)
(7, Seven)
(8, Eight)
(9, Nine)
See APPENDIX B for the map and multimap class definitions
See APPENDIX C for a table of map and multimap methods
See APPENDIX D for an explanation of the allocator class (fourth template parameter above)
I hope this is what you were looking for.