Re: STL map insert Options
mrc2323@cox.net (Mike Copeland) wrote in news:MPG.287d2c69abea9b739896c0
@news.eternal-september.org:
Ian already answered your main questions I think, here are just some
comments about typedefs.
typedef struct ChipRec
{
int bibNum;
char cEvent;
unsigned int finTime;
} TData;
The above typedef is not useful as you effectively create two names
(ChipRec and TData) meaning the same thing, which can only cause
confusion later. This technique is used only in C as in C the two names
are not identic (one has to be always used with 'struct' keyword, the
other not). When encountered in a C++ program, this is classified as a C-
ism.
TData tWork;
typedef map<int, ChipRec> BCI;
This typedef OTOH is useful as it helps to shorten other code and makes
it easier to cope with changes (e.g. using a hash map instead of map).
BCI bci;
map<int, ChipRec>::iterator bciIter;
Should be BCI::iterator bciIter;
int main()
{
tWork.bibNum = 2066, tWork.cEvent = 'a', tWork.finTime = 0;
bci.insert(BCI::value_type(tWork.bibNum, tWork));
Why not
bci[tWork.bibNum] = tWork;
(OK, there are semantic differences if the key already exists.)
hth
Paavo