Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Range fancify please
From: anony (janezz55_at_[hidden])
Date: 2009-12-27 11:57:17


OvermindDL1 pravi:
> 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

I guess Boost.Lambda would work also in this case :) Good idea.


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