[array] Misc comments

Hi, some misc, quick, comments about boost array: * the current CVS version has the required partial specialization for the case N==0; I haven't actually compiled it, but I suppose <http://sourceforge.net/tracker/index.php?func=detail&aid=1484104&group_id=7586&atid=107586> should be closed. * in the mentioned specialization (I haven't checked the primary template, maybe there too), there are many repetitions of: failed_rangecheck(); return null_item(); Anywhere this is used the return type is either reference or const_reference, so one could replace all of those occurrences with: return failed_function(); where failed_function() is defined as static reference failed_function() { failed_rangecheck(); return null_item(); } For additional safety, functions returning a const_reference ought to do: return static_cast<const_reference>(failed_function()); NOTE: Going a bit further null_item() is not necessary, as one could use a return *(new T) directly in failed_range_check(), though I haven't thought of all the consequences in the case operator new is overloaded. * why are the two operator[]() functions range-checked for the case N==0? And what's the point of those BOOST_ASSERT( "out of range" )? --Gennaro.

Gennaro Prota wrote:
<http://sourceforge.net/tracker/index.php?func=detail&aid=1484104&group_id=7586&atid=107586>
should be closed.
Done.
* in the mentioned specialization (I haven't checked the primary template, maybe there too), there are many repetitions of:
failed_rangecheck(); return null_item();
Anywhere this is used the return type is either reference or const_reference, so one could replace all of those occurrences with:
return failed_function();
where failed_function() is defined as
static reference failed_function() { failed_rangecheck(); return null_item(); }
Yep that can be simplied quite a bit, done in cvs. I haven't added the static_cast's: it obfuscates the code and serves no real purpose - no value can actually ever be returned.
NOTE: Going a bit further null_item() is not necessary, as one could use a return *(new T) directly in failed_range_check(), though I haven't thought of all the consequences in the case operator new is overloaded.
Not so sure about that.
* why are the two operator[]() functions range-checked for the case N==0? And what's the point of those BOOST_ASSERT( "out of range" )?
No idea - Alistair? I've removed them for now since they serve no purpose that I can see: they'll always pass won't they? John.

On Sat, 24 Jun 2006 12:34:43 +0100, "John Maddock" <john@johnmaddock.co.uk> wrote:
Gennaro Prota wrote:
[...]
Yep that can be simplied quite a bit, done in cvs. I haven't added the static_cast's: it obfuscates the code and serves no real purpose - no value can actually ever be returned.
Thanks, I could have done that myself, but I always prefer to ask for the original developer, first, just to be sure I'm not missing anything.
NOTE: Going a bit further null_item() is not necessary, as one could use a return *(new T) directly in failed_range_check(), though I haven't thought of all the consequences in the case operator new is overloaded.
Not so sure about that.
Yeah, of course the type of the expression *(new T) would always be T, but I'm not sure if it may cause code bloat in case the compiler is not able to see that it is never reached. After a couple of nights of sleep I find the static T solution preferable.
* why are the two operator[]() functions range-checked for the case N==0? And what's the point of those BOOST_ASSERT( "out of range" )?
No idea - Alistair?
I've removed them for now since they serve no purpose that I can see: they'll always pass won't they?
Tricky question. IMHO it is undefined behavior. When BOOST_ASSERT falls back to the standard assert it really depends on the underlying library. C90 does not require that assert works with expressions having non-int type. In C99 it shall work for any scalar expression (which anyway "out of range" is not; it has array type). We could perhaps protect against this kinds of things by using a static_cast in assert.hpp (probably documenting that) --Gennaro.

Gennaro Prota wrote:
We could perhaps protect against this kinds of things by using a static_cast in assert.hpp (probably documenting that)
Right, but I still don't know what it was supposed to do in the first place, if it was supposed to always fail then it should have been: BOOST_ASSERT(0 == "Some string"); John.
participants (2)
-
Gennaro Prota
-
John Maddock