|
Boost Users : |
Subject: [Boost-users] [Boost.Assign] list_of::range without an initial (single) element?
From: Michael McNeil Forbes (michael.forbes_at_[hidden])
Date: 2010-06-13 04:11:44
What is the recommended way of initializing an array from a
concatenation of other arrays?
list_of::range looks right and I would like to use something like:
array<int, 2> a = { 1, 2 };
array<int, 2> b = { 3, 4 };
array<int, 4> c = list_of<int>().range(a).range(b);
However, list_of<int>() inserts a default value (so that
list_of<int>().range(a).range(b) == {0,1,2,3,4}). There are several
workarounds, e.g.
array<int, 4> c = list_of<int>(a[0])
.range(a.begin()+1, a.end())
.range(b);
array<int, 4> c = boost::assign_detail::generic_list<int>()
.range(a)
.range(b);
The first is ugly; the second seems an abuse of assign_detail (and
fails for static_generic_list).
I am sure I am missing a simple solution, but can't seem to find it.
Thanks,
Michael.
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