Boost logo

Boost :

From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2007-07-11 09:48:25


On 10/07/07, Marat Khalili <0x8.0p15_at_[hidden]> wrote:
> Are there any standard means to clone collection class while changing
> only element type? Like receiving some_collection<int> as a template
> parameter and creating some_collection<string> without knowing what
> exactly some_collection is.
>
It seems like a std::transform with a type conversion func and into an
insert iterator would do the job, or an iterator range constructor
from some kind of transform_iterator that I'm sure is in boost
somewhere.

std::vector<int> vi;
v += 1,2,3,4,5;
std::vector<std::string> vs;
std::transform( vi.begin(), i.end(),
   std::back_inserter(vs),
   &boost::lexical_cast<std::string,int> );

HTH,
~ Scott McMurray

P.S. We have containers in C++, not collections.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk