Boost logo

Boost Users :

Subject: Re: [Boost-users] [range] What's the best way to initialize a new container from a range?
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2011-09-03 07:11:22


Den 26-08-2011 14:30, Martin B. skrev:
> Hi!
>
> Say I have a range R and I want to construct a new container from the
> range R. Will I always have to repeat the expression yielding the range,
> or is there a shorter way?
>
> Example:
>
> std::vector<int> numbers(
> boost::irange(7, 42).begin(),
> boost::irange(7, 42).end()
> );
>
> Note that it's just an example.
>
> Is it possible to create a container C from a range expression R in one
> step? Any helper function for this?
>

std::vector<int> numbers =
        boost::copy_range<std::vector<int>>( boost::irange(7,42) );

-Thorsten


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