Click here to Skip to main content
15,915,824 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
AnswerRe: unhandle exception(8000ffff) while acceing ocx methods Pin
Michael Dunn19-Nov-05 15:18
sitebuilderMichael Dunn19-Nov-05 15:18 
AnswerRe: unhandle exception(8000ffff) while acceing ocx methods Pin
JonEngle6-Dec-05 19:16
JonEngle6-Dec-05 19:16 
QuestionHow to access method of user define control from ATL Pin
rajesh_kapure16-Nov-05 3:54
rajesh_kapure16-Nov-05 3:54 
QuestionUsing ActiveX without container Pin
Ahsan Askare14-Nov-05 23:33
Ahsan Askare14-Nov-05 23:33 
QuestionHow do you know the duplicate key insertion in STL map Pin
sarath_babu13-Nov-05 20:23
sarath_babu13-Nov-05 20:23 
AnswerRe: How do you know the duplicate key insertion in STL map Pin
Jonas Larsson13-Nov-05 21:50
Jonas Larsson13-Nov-05 21:50 
GeneralRe: How do you know the duplicate key insertion in STL map Pin
sarath_babu14-Nov-05 0:09
sarath_babu14-Nov-05 0:09 
GeneralRe: How do you know the duplicate key insertion in STL map Pin
Jonas Larsson14-Nov-05 1:50
Jonas Larsson14-Nov-05 1:50 
Some of your post was eaten and it's still not clear to me if you want to know if an item was a dublicate before or after you insert it into the map.

Here's your code (rewritten some so I could get it to compile)

[Edited:] Doh! I was under the impression that map<>::insert updates an elemet already in the map. That is not correct, sorry for the confusion! D'Oh! | :doh:

#include <iostream>
#include <map>
#include <boost\shared_ptr.hpp>
using namespace std;


class A
{
unsigned long la;
unsigned long lb;
unsigned long lc;
public:
A() : la(0), lb(0), lc(0) {}
A(unsigned long ln,unsigned long lm,unsigned long lo): la(ln), lb(lm), lc(lo) {}
A(const A& o) : la(o.la), lb(o.lb), lc(o.lc) {}

bool operator==(const A& o) const
{
return la == o.la && lb == o.lb && lc == o.lc;
}

bool operator !=(const A& o) const
{
return !(*this == o);
}

unsigned long sum()
{
return (la+lb+lc);
}

bool operator < (const A& o) const
{
if (la == o.la)
if (lb == o.lb)
return lc < o.lc;
else
return lb < o.lb;
else
return la < o.la;
}

friend ostream& operator<<(ostream& out, const A& o);
};


ostream& operator<<(ostream& out, const A& o)
{
out<<"("<<o.la<<","<<o.lb<<","<<o.lc<<")";
return out;
}

namespace std { // needed for std::copy to work
ostream& operator<<(ostream& out, const pair<A, boost::shared_ptr<float> >& o)
{
out << "[" << o.first << "," << *(o.second) << "]";
return out;
}
}

typedef std::map<A, boost::shared_ptr<float> > Aptrmap;

bool is_duplicate(const Aptrmap& themap, const A& o)
{
return themap.find(o) != themap.end();
}

int main(int argc, char* argv[])
{
A objOne(0,1,2);
A objTwo(0,1,2);
A objThree(0,1,1);
A objFour(0,1,2);
A objFive(4,4,5);

boost::shared_ptr<float> pfa(new float(1.10)),
pfb(new float(2.20)),
pfc(new float(3.30)),
pfd(new float(4.40)),
pfe(new float(5.50));

Aptrmap objmap;
pair <Aptrmap::iterator, bool> it;
it =objmap.insert(std::make_pair(objFive,pfe));
// check if we inserted a new value or updated an old item
if (it.second)
cout << *(it.first) << " was inserted" << endl;
else
cout << *(it.first) << " was a duplicate" << endl;

// objmap[objFive]=pfe;
it =objmap.insert(std::make_pair(objOne,pfa));
// check if we inserted a new value or updated an old item
if (it.second)
cout << *(it.first) << " was inserted" << endl;
else
cout << *(it.first) << " was a duplicate" << endl;
it =objmap.insert(std::make_pair(objTwo,pfb));
// check if we inserted a new value or updated an old item
if (it.second)
cout << *(it.first) << " was inserted" << endl;
else
cout << *(it.first) << " was a duplicate" << endl;
it =objmap.insert(std::make_pair(objThree,pfc));
// check if we inserted a new value or updated an old item
if (it.second)
cout << *(it.first) << " was inserted" << endl;
else
cout << *(it.first) << " was a duplicate" << endl;

// check if this value is a duplicate before inserting
if (!is_duplicate(objmap, objFour))
{
it =objmap.insert(std::make_pair(objFour,pfd));
if (it.second)
cout << *(it.first) << " was inserted" << endl;
}
else
cout << objFour << " was a duplicate, will not insert it" << endl;

boost::shared_ptr<float> pf(new float(9));
objmap[objThree]=pf;

// print all element values
copy(objmap.begin(), objmap.end(), ostream_iterator<pair<A, boost::shared_ptr<float> > >(cout, "\n"));

Aptrmap::const_iterator posTwo=objmap.find(objThree);
if (posTwo != objmap.end())
cout<<*(posTwo->second)<<endl;

Aptrmap::const_iterator posTwo1=objmap.find(objFive);
if (posTwo1 != objmap.end())
cout<<*(posTwo1->second)<<endl;

return 0;
}

HTH


---

"Man will never be free until the last king is strangled with the entrails of the last priest". -- Denis Diderot


-- modified at 8:49 Monday 14th November, 2005&gt;&gt;
GeneralRe: How do you know the duplicate key insertion in STL map Pin
Stuart Dootson15-Nov-05 6:53
professionalStuart Dootson15-Nov-05 6:53 
GeneralRe: How do you know the duplicate key insertion in STL map Pin
Jörgen Sigvardsson15-Nov-05 9:59
Jörgen Sigvardsson15-Nov-05 9:59 
GeneralRe: How do you know the duplicate key insertion in STL map Pin
Stuart Dootson15-Nov-05 19:54
professionalStuart Dootson15-Nov-05 19:54 
GeneralRe: How do you know the duplicate key insertion in STL map Pin
Jörgen Sigvardsson15-Nov-05 21:14
Jörgen Sigvardsson15-Nov-05 21:14 
GeneralRe: How do you know the duplicate key insertion in STL map Pin
Stuart Dootson15-Nov-05 21:24
professionalStuart Dootson15-Nov-05 21:24 
GeneralRe: How do you know the duplicate key insertion in STL map Pin
Tim Smith23-Nov-05 4:05
Tim Smith23-Nov-05 4:05 
QuestionCommand Line AND a window? Pin
micr0chip12-Nov-05 1:40
micr0chip12-Nov-05 1:40 
AnswerRe: Command Line AND a window? Pin
Michael Dunn13-Nov-05 12:54
sitebuilderMichael Dunn13-Nov-05 12:54 
GeneralRe: Command Line AND a window? Pin
micr0chip15-Nov-05 6:25
micr0chip15-Nov-05 6:25 
Questionupload binary file using webservices Pin
Liu Shuai8-Nov-05 15:58
Liu Shuai8-Nov-05 15:58 
QuestionHow to handle ctrl+c etc in Shell Extension Pin
Solidcore8-Nov-05 0:15
Solidcore8-Nov-05 0:15 
QuestionHow to create a Service using ATL Pin
snprani7-Nov-05 19:02
snprani7-Nov-05 19:02 
AnswerRe: How to create a Service using ATL Pin
G Haranadh7-Nov-05 19:49
G Haranadh7-Nov-05 19:49 
QuestionActivex Versioning Pin
omaycotte7-Nov-05 10:17
omaycotte7-Nov-05 10:17 
Questionadd page in property sheet Pin
Maddie from Dartford6-Nov-05 19:23
Maddie from Dartford6-Nov-05 19:23 
AnswerRe: add page in property sheet Pin
srinivasa rao dutta12-Nov-05 0:53
srinivasa rao dutta12-Nov-05 0:53 
QuestionGetting messages generated by toolbar buttons click? Pin
Roozbeh693-Nov-05 8:07
professionalRoozbeh693-Nov-05 8:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.