shetlandbob
Programmer
Morning all,
This is more a general question that an actual problem to solve:
I set up the following:
Is the above code legal? It compiles and so far it works, I only came across it by accident as I used to use:
If they are both acceptable and legal ways to access. Is there a performance overhead in using one way over the other? Some of my code has multi million elements in my map so this may have an implication?
Any comments much appreciated
This is more a general question that an actual problem to solve:
I set up the following:
Code:
myOwnStructure mystruct; [green]// this is defined elsewhere[/green]
map<int, mystuct> myMap;
[green]
// then elsewhere in my code
// i loop through this and add in multiple mystructs.
[/green]
int myInt;
typedef pair <int, mystruct> mapPair;
myMap.insert ( mapPair ( myInt, mystruct ) );
[green]
// my int is an integer that varies between 1 - 100000
//
// then elsewhere in my code I want to access my map
[/green]
int myIntToRecall;
myOwnStructure* pStruct;
pStruct = &myMap[myIntToRecall];
Is the above code legal? It compiles and so far it works, I only came across it by accident as I used to use:
Code:
int myIntToRecall;
myOwnStructure* pStruct;
map < int, mystruct >::iterator it;
for ( it = myMap.begin(); it != myMap.end(); it++ )
{
if ( it->first == myIntToRecall )
{
pStruct = it->second;
}
}
If they are both acceptable and legal ways to access. Is there a performance overhead in using one way over the other? Some of my code has multi million elements in my map so this may have an implication?
Any comments much appreciated