Boost Users :
Subject: Re: [Boost-users] Boost.Range fancify please
From: Patrick Horgan (phorgan1_at_[hidden])
Date: 2009-12-27 20:29:31
That's referring to a dimension 1 array explicitly, so doesn't have much bearing on this. In particular a two dimension array data is built by a compiler like this:The make_iterator_range() function sees only 2 pointers and these are all it cares about. Now, let's check the standard: ISO-IEC-14882 Section 8.3.4 Array, page 137: An object of array type contains a contiguously allocated non- empty set of N sub-objects of type T.
Yes, it shows what your compiler implements in this circumstance, but tells you nothing about what will be done by other compilers, or by your own compiler in all circumstances. When you take advantage of implementation defined behavior, you're gambling with no guarantees except that if it fails it's your fault and you don't get to complain to the compiler implementor.The pointers I provide point to the beginning and the end of the vertices multidimensional array. The array must be contiguously allocated, as specified in the standard, hence I don't see which aspect of what I am doing in undefined, if the functions boost::begin() and boost::end() work as expected (again, they return pointers, not fancy iterator objects). Did I mention the debugger shows everything is just perfect.
It's pretty normal to use nested loops for nested elements, and prettily enough, you are dealing with each element, scaling it, so this is a perfect use of foreach. I think it's quite elegant, both generating minimal assembler and being clear and maintainable.Why not just use BOOST_FOREACH correctly? BOOST_FOREACH(float (&rgf), vertices) BOOST_FOREACH(float& f, rgf) f *= scale;Double loop, oops. Not fancy enough.Are you joking?I was looking for fancy (i.e. elegant) code, yours is too complicated.
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