M
Mike Copeland
I am curious about the benefits of several STL map usages and
interfaces. Consider the following declarations:
class Entrant
{
public:
int baseBib;
char baseEvent;
unsigned int specTime;
} ;
int main()
{
map<int, Entrant> myEntrant;
map<int, Entrant>::iterator it;
Entrant a1;
a1.baseBib = 2066, a1.baseEvent = 'a', a1.specTime = 0;
myEntrant.insert(pair<int, Entrant>(a1.baseBib, a1));
[etc.]
....and:
typedef struct ChipRec
{
int bibNum;
char cEvent;
unsigned int finTime;
} TData;
TData tWork;
typedef map<int, ChipRec> BCI;
BCI bci;
map<int, ChipRec>::iterator bciIter;
int main()
{
tWork.bibNum = 2066, tWork.cEvent = 'a', tWork.finTime = 0;
bci.insert(BCI::value_type(tWork.bibNum, tWork));
[etc.]
In both declarations I'm doing the same work, but I can't see any
advantage to either (class or typedef struct declarations)...other than
minor coding differences. Am I missing something that _is_ a reason to
use one technique versus another?
Also, I see some references to "make_pair", but I don't understand
what that is nor why/how I might use that construct in my applications.
Could someone explain the 3 constructs "pair", "make_pair" and
"value_type"? TIA
interfaces. Consider the following declarations:
class Entrant
{
public:
int baseBib;
char baseEvent;
unsigned int specTime;
} ;
int main()
{
map<int, Entrant> myEntrant;
map<int, Entrant>::iterator it;
Entrant a1;
a1.baseBib = 2066, a1.baseEvent = 'a', a1.specTime = 0;
myEntrant.insert(pair<int, Entrant>(a1.baseBib, a1));
[etc.]
....and:
typedef struct ChipRec
{
int bibNum;
char cEvent;
unsigned int finTime;
} TData;
TData tWork;
typedef map<int, ChipRec> BCI;
BCI bci;
map<int, ChipRec>::iterator bciIter;
int main()
{
tWork.bibNum = 2066, tWork.cEvent = 'a', tWork.finTime = 0;
bci.insert(BCI::value_type(tWork.bibNum, tWork));
[etc.]
In both declarations I'm doing the same work, but I can't see any
advantage to either (class or typedef struct declarations)...other than
minor coding differences. Am I missing something that _is_ a reason to
use one technique versus another?
Also, I see some references to "make_pair", but I don't understand
what that is nor why/how I might use that construct in my applications.
Could someone explain the 3 constructs "pair", "make_pair" and
"value_type"? TIA