My goal is to store all the keys of a map (first item) to a vector and I'm doing the following.
template < class vecDet>
class storeInto
{
public:
storeInto(vecDet& source) : VectorInfo(source) { }
~storeInto();
template <class pairdet>
void operator()(pairdet& pairinfo)
{
VectorInfo.push_back(pairinfo.first);
}
private:
vecDet& VectorInfo;
};
template<class mapDet, class vecDet>
void storeMapToVector(const mapDet& mapContA, vecDet& vecContA)
{
for_each(mapContA.begin(), mapContA.end() , storeInto<vecDet>(vecContA));
}
Finally, from my main program, I'm calling the storeMapToVector() as follows
storeMapToVector<mapinfo,vector<char> >(mapContents, vecContents);
where mapinfo is declared as follows
typedef map<char,int> mapinfo;
Is there a better way to do this? Is there anything wrong with this?