On 9/19/06, Alexander Shyrokov <shirokov@unh.edu> wrote:
I want to convert values according to a map before inserting it into the
list. What is a proper way to do that?
I have this:
map<int,int> m;
vector<int> a,b;
for(vector<int>const_iterator i=
a.begin();i!=a.end();++i)
b.push_back(m[*i]);
I could use std::copy with std::back_inserter to add elements to b, but
how do I convert it first? Should I write my own version of
back_inserter for that?
copy(a.begin(),a.end(),my_back_inserter(b,m));
Thanks.
--
Regards,
Alexander. http://sjcomp.com
I would probably write
for(vector<int>const_iterator i=a.begin();i!=a.end();++i)
b.push_back(m[*i]);
(yes, I understand that's your original.)
Tony