STL map ( no unique element )
Are there any experts out there ?
I know STL map only allow unique key but how about its element ?
I want the element to be unique too. Is there an easy way to do it ?
I can compare every element in the map and make sure it's unique but i am posting here for a better way.
eg grade_list["john"] = 'A';
The 'A' is the element and i want it to be unique for all element in the map. There's a reason for what i am doing.
I don't want to create additional set structure.
Either you can write a wrapper or try some customized STL (i guess few are available as part of ACE)
It seems like i have to compare every element in the map.
so is this efficient enough ?
If not, please suggest a better solution.
for(iter = mymap.begin(); iter != mymap.end(); iter++)
cout << endl;
for(iter1 = mymap.begin(); iter1 != mymap.end(); iter1++)
if(*iter != *iter1)
// if two elements are equal, then print out "Equal"
cout << " iter: " << iter->second << " iter1: " << iter1->second << endl;
I would use a different approach: instead of storing the name as the key, use the grade as the associated value (what you call "the element"). Alternatively, use the unique(), remove_if() etc. algorithms to ensure uniqueness of the map's elements.
Last Post: 12-05-2006, 05:35 PM
Last Post: 01-15-2006, 08:10 PM
By Elisabeth in forum XML
Last Post: 09-21-2001, 10:26 AM
Last Post: 06-25-2001, 05:06 AM
Last Post: 04-29-2001, 06:01 PM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center