Re: Using unique with std::map
On Mar 27, 1:01 pm, Carl Barron <cbarron...@adelphia.net> wrote:
If you want a collection of pairs with unique first and second values
then perhaps a std::set<std::pair<int,std::string> > is more
appropriate
as it won't store duplicate entries so it would only contain
pair(1,"aaa") and pair(2,"bbb"). Pair(3,"aaa") would not be inserted.
const char *text[] = {"aaa","bbb","aaa",0};
std::set<std::pair<int,std::string> > s;
const char **p = text;
for(int i=0;*p;++i,++p)
{
s.insert(std::pair<int,std::string>(i,*p);
}
done.
Thanks, but the code above will store all 3 pairs in the set, since
pair(1,"aaa") != pair(3,"aaa").
Actually I started with std::set<std::string> as to store unique
values, but then I realized that I want to retain the keys as well,
hence I came up to std::pair<std::string, std::vector<int> >
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]