Boost logo

Boost Users :

Subject: [Boost-users] [Range] concatenate 2 vectors
From: Christophe B. (boost_at_[hidden])
Date: 2015-03-13 08:56:50


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


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