OvermindDL1 pravi:
On Sat, Dec 26, 2009 at 8:33 PM, anony
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
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
,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.