Fedora Linux Support Community & Resources Center
  #1  
Old 24th February 2007, 07:55 AM
overule Offline
Registered User
 
Join Date: Aug 2005
Location: Australia
Posts: 289
Exclamation STL map ( no unique element )

Hi there,

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.

Please help.

cheers
Reply With Quote
  #2  
Old 24th February 2007, 08:37 AM
markkuk Offline
Registered User
 
Join Date: Apr 2005
Location: Finland
Posts: 5,075
Create an additional std::set for the element values, then you can easily test if an element already exists.
Reply With Quote
  #3  
Old 24th February 2007, 08:39 AM
overule Offline
Registered User
 
Join Date: Aug 2005
Location: Australia
Posts: 289
Can you show me any example (in code form)?
I dont get what you meant.

thanks
Reply With Quote
  #4  
Old 24th February 2007, 11:06 AM
overule Offline
Registered User
 
Join Date: Aug 2005
Location: Australia
Posts: 289
I don't want to use additional structure. That's not the right way to use set anyway.

There must be a better way!
Reply With Quote
  #5  
Old 25th February 2007, 08:06 AM
overule Offline
Registered User
 
Join Date: Aug 2005
Location: Australia
Posts: 289
It seems like i have to compare every element in the map.

so is this efficient enough ?

Code:
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"
        		if()
        		cout << " iter: " << iter->second << " iter1: " << iter1->second << endl;
        	}
        }
  
    }
If not, please suggest a better solution.

thanks
Reply With Quote
Reply

Tags
element, map, stl, unique

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A very unique requirement, I guess! petervoldon Using Fedora 13 14th October 2008 05:26 AM
Unique Problem (I THink) PLEASE HELP DMD Hardware & Laptops 0 10th June 2006 06:17 PM
Installation help... unique problem ajhtiredwolf Installation, Upgrades and Live Media 13 16th August 2005 06:42 AM
Bad font path element davids Using Fedora 0 6th August 2005 10:48 AM


Current GMT-time: 09:24 (Thursday, 23-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Khalilabad Instagram Photos - Yigou Photos on Instagram - Bracken Ridge Travel Photos