I have a vector of strings and I have a map that maps one string to
another. How can use transform for that?
This is how I do it right now:
map mapping;
vector<string> strings;
for(vector<string>::iterator s=strings.begin();s!=strings.end();++s)
*s=mapping[*s];
I would like something like:
transform(strings.begin(),strings.end(),strings.begin(),_1=mapping[_1]);
Or maybe there is a predicate that already does it? I can write my own:
template<T> struct mapit: public unary_function
{
map mapping;
mapit(const map& m):mapping(m){}
T operator()(const T& s){return mapping[s];}
}
transform(strings.begin(),strings.end(),strings.begin(),mapit<string>(mapping));
Is it the proper way to do such a transformation?
Thanks.
--
Regards,
Alexander. http://sjcomp.com