Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Range fancify please
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-12-27 00:49:22


On Sat, Dec 26, 2009 at 10:45 PM, OvermindDL1 <overminddl1_at_[hidden]> wrote:
> On Sat, Dec 26, 2009 at 8:33 PM, anony <janezz55_at_[hidden]> wrote:
>> I have this variable definition:
>>
>> float vertices[][3] = {
>>  {-1, -1,  1}, {1, -1,  1}, {1, 1,  1}, {-1, 1,  1},
>>  {-1, -1, -1}, {1, -1, -1}, {1, 1, -1}, {-1, 1, -1}
>>  };
>>
>> I want to scale all elements of vertices, by some constant, for now I do
>> it like this:
>>
>> BOOST_FOREACH(float& f, boost::make_iterator_range(
>>  boost::begin(vertices[0]), boost::end(vertices[7])))
>> {
>>  f *= scale;
>> }
>
> Are you sure that is correct, you are only multiplying the first 7
> floats (out of 8*3=24)...
>
>
> On Sat, Dec 26, 2009 at 8:33 PM, anony <janezz55_at_[hidden]> wrote:
>> But maybe something more beautiful could be done with Boost.Range?
>
> Actually you could make it more 'beautiful' (as in shorter code) using
> fusion+phoenix if it really is a constant sized array like you have.
>
> This is probably not correct, but I am at work right now so cannot check:
>
> using namespace boost::fusion; using namespace boost::phoenix; using
> boost::array;
>
> array<array<float,3>,8> vertices = {
>  {-1, -1,  1}, {1, -1,  1}, {1, 1,  1}, {-1, 1,  1},
>  {-1, -1, -1}, {1, -1, -1}, {1, 1, -1}, {-1, 1, -1}
>  };
>
> for_each(vertices,arg0*=val(scale));  // one line of code
>
> Else, if it is not a static size, then yeah, do what Eric said, even
> then his way is short enough that you may as well use it regardless.
>

Er, you will need to joint view the sub array parts or something. It
is easy to do, I am just a bit brain-dead right now, sleep...


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