[Range] concatenate 2 vectors
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
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
participants (2)
-
Christophe B.
-
Jeff Flinn