Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost.Assign] list_of::range without an initial (single) element?
From: er (erwann.rogard_at_[hidden])
Date: 2010-06-15 10:37:00


Michael McNeil Forbes wrote:
> 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.

The proposed extension of Boost.Assign offers an alternative approach to
this problem:

     boost::array<int, 2> a = { 1, 2 };
     boost::array<int, 2> b = { 3, 4 };
     boost::array<int, 4> c = a && b;

I have reproduced this example at the bottom of this file:
http://svn.boost.org/svn/boost/sandbox/statistics/support/libs/assign/example/range.cpp.

Instructions are here:
http://svn.boost.org/svn/boost/sandbox/statistics/support/libs/assign/doc/patch.txt


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