STL Initialisation

Joined
Apr 28, 2008
Messages
1
Reaction score
0
Hi Folks,
Newly back to c++ after about 6 years so I am extremely rusty. I managed to get the following code to work.

std::pair<int, Creator*> initMap[] = {
// sig Id CTor
// ------ -------------------------
std::pair<int, Creator*>(1, new CreateOne()),
std::pair<int, Creator*>(2, new CreateTwo()),
std::pair<int, Creator*>(3, new CreateThree())
};

template<typename T, std::size_t z> std::size_t size(T const (&a)[z]) {
return z;
}

FactoryInstance::FactoryInstance()
: sig2Hdlr(std::map<int, Creator*>(initStdMap,initStdMap+size(initStdMap))),
FactoryBaseClass(&sig2Hdlr)
{
}


Could someone please help me unnderstand this by explaining the following:

template<typename T, std::size_t z> std::size_t size(T const (&a)[z]) {
return z;
}

where the function template is instantiated with size(initStdMap) //where the type of initStdMap is std::pair<int, Creator*> * How does it work?

Cheers,
DLT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top