Boost logo

Boost Users :

From: Hughes, James (jhughes_at_[hidden])
Date: 2006-09-19 10:02:03


 

> -----Original Message-----
> From: boost-users-bounces_at_[hidden]
> [mailto:boost-users-bounces_at_[hidden]] On Behalf Of
> Alexander Shyrokov
> Sent: 19 September 2006 14:19
> To: boost-users_at_[hidden]
> Subject: [Boost-users] converting value before inserting into a list
>
> 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 probably being very anti-modern C++ here, but I think that the for
loop takes a lot of beating for readability......its probably the most
efficient too (with a bit of cacheing of invarients)......

I do find that some of these so called 'helpers' do make the code more
obscure, but that's perhaps because I have spent 15 years doing C then
C++, rather than solely starting with C++.

James

> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

This message (including any attachments) contains confidential
and/or proprietary information intended only for the addressee.
Any unauthorized disclosure, copying, distribution or reliance on
the contents of this information is strictly prohibited and may
constitute a violation of law. If you are not the intended
recipient, please notify the sender immediately by responding to
this e-mail, and delete the message from your system. If you
have any questions about this e-mail please notify the sender
immediately.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net