Boost logo

Boost Users :

Subject: Re: [Boost-users] [Range] concatenate 2 vectors
From: Jeff Flinn (jeffrey.flinn_at_[hidden])
Date: 2015-03-14 19:22:30


On 3/13/15 8:56 AM, Christophe B. wrote:
> Hi all,
>
> I want to construct a static const vector being the result of
> concatenation of two other vectors. I was thinking to use
> boost::push_back, but it takes a container as a lvalue reference as a
> 1st argument. I could develop the following piece of code
>
> template <typename Container, typename Range>
> Container concat(Container const &c, Range cont& r)
> {
> Container result = c;
> return boost::push_back(result, r);
> }
>
> static const std::vector<std::string> v = concat(v1, v2);
>
> But I wanted to avoid to reinvent the wheel. Currently, I am living with
> this kind of writing:
>
> static const auto v = [&]{
> std::vector<std::string> result = v1;
> return boost::push_back(result, v2);
> }();
>
> Does boost libraries offer a better alternative to this construct ?
>
> Christophe

Something like this:

using namespace boost;

std::vector<std::string> v
        = copy_range<std::vector<std::string>>( join( c, r ) );

Jeff


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