[boost] Re: ENFORCE

2003-05-08 Thread Daniel Frey
Gennaro Prota wrote:
On Thu, 8 May 2003 15:06:02 +0300, John Torjo [EMAIL PROTECTED]
wrote:
Unfortunately, we can't use the do-while(0) idiom, since we don't know when
while(0) will be ;-)
Oops, no. That's not the problem. The problem is that I read Daniel's
reply out of context and too absent-mindedly :-) I thought it was
something like
  if (false) ; else

whereas he is really testing for a condition

  if(expr)...

However, if you are going to abort at the end (or throw, but I don't
want to enter in this matter) you can simply replace 'if' with
'while':
But that does not give you any benefit at all, does it? The 
do-while-idiom is very different from the while-version you suggest. 
It's IMHO the only idiom that forces the user to add a semicolon, but we 
actually don't want to do that here. The user should be allowed to add 
(i) or other stuff. I think that the 'if' (or 'while', but that's not a 
difference) is the best we can do here.

Regards, Daniel

--
Daniel Frey
aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: [EMAIL PROTECTED], web: http://www.aixigo.de
___
Unsubscribe  other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Re: [boost] Re: ENFORCE

2003-05-08 Thread Paul Mensonides
Gennaro Prota wrote:

 Just that Borland won't warn on BOOST_INVARIANT(false). Admittedly
 not a big one :-)

This warning can be configured away simply by purposely accessing a non-constant
variable or calling an inline function:

inline bool force_non_constant() { return true; }

if (force_non_constant(), expr) else ...

Regards,
Paul Mensonides

___
Unsubscribe  other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


[boost] Re: ENFORCE

2003-04-26 Thread Andrei Alexandrescu
David Abrahams [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Andrei Alexandrescu [EMAIL PROTECTED] writes:

  By the way, I believe what would be more interesting for Boost is the
  recent article (http://www.cuj.com/experts/2106/alexandr.htm), written
by
  Petru Marginean and myself. (Warning - the article has recently been
  updated.)
 
  We have good experience in reducing source code size by using
enforcements.
  There are a number of interesting techniques used out there, and I
believe
  ENFORCE would be quite useful as a Boost library.

 I browsed the article (I confess to not having read everything, so
 please correct any misapprehensions).  My sense is that the technique
 is oriented towards detecting programmer errors and responding via an
 exception.

No.

Andrei



___
Unsubscribe  other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


[boost] Re: ENFORCE

2003-04-26 Thread Edward Diener
David Abrahams wrote:
 Andrei Alexandrescu [EMAIL PROTECTED] writes:

 By the way, I believe what would be more interesting for Boost is the
 recent article (http://www.cuj.com/experts/2106/alexandr.htm),
 written by Petru Marginean and myself. (Warning - the article has
 recently been
 updated.)

 We have good experience in reducing source code size by using
 enforcements. There are a number of interesting techniques used out
 there, and I believe ENFORCE would be quite useful as a Boost
 library.

 I browsed the article (I confess to not having read everything, so
 please correct any misapprehensions).  My sense is that the technique
 is oriented towards detecting programmer errors and responding via an
 exception.

I don't think ENFORCE is oriented toward that at all. There's no orientation
involved other than to throw an exception based on a condition. I agree with
you that direct programming errors should generally not throw exceptions but
should ASSERT so that the programmer can fix the error. However I don't
think ENFORCE has anything to do with this debate about when to ASSERT and
when to throw exceptions. Perhaps the examples give the impression which you
have, but I think the problem is just choosing better examples in which one
would want to throw an exception and not a technical issue as to the
benefits of using ENFORCE in order to simplify exception throwing.



___
Unsubscribe  other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Re: [boost] Re: ENFORCE

2003-04-26 Thread David Abrahams
Andrei Alexandrescu [EMAIL PROTECTED] writes:

 I browsed the article (I confess to not having read everything, so
 please correct any misapprehensions).  My sense is that the technique
 is oriented towards detecting programmer errors and responding via an
 exception.

 No.

Please correct my misapprehension then.  I did go back and read more
carefully without getting a different impression.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

___
Unsubscribe  other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Re: [boost] Re: ENFORCE

2003-04-26 Thread David Abrahams
Edward Diener [EMAIL PROTECTED] writes:

 I browsed the article (I confess to not having read everything, so
 please correct any misapprehensions).  My sense is that the technique
 is oriented towards detecting programmer errors and responding via an
 exception.

 I don't think ENFORCE is oriented toward that at all. There's no orientation
 involved other than to throw an exception based on a condition. I agree with
 you that direct programming errors should generally not throw exceptions but
 should ASSERT so that the programmer can fix the error. However I don't
 think ENFORCE has anything to do with this debate about when to ASSERT and
 when to throw exceptions. Perhaps the examples give the impression which you
 have

I think so.

 but I think the problem is just choosing better examples in which
 one would want to throw an exception and not a technical issue as to
 the benefits of using ENFORCE in order to simplify exception
 throwing.

Can you show me a better example?  This is not a challenge.  Really,
if this ENFORCE idea is a useful one I want to understand it.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

___
Unsubscribe  other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Re: [boost] Re: ENFORCE

2003-04-26 Thread Tanton Gibbs
From: David Abrahams [EMAIL PROTECTED]
 Edward Diener [EMAIL PROTECTED] writes:

  I browsed the article (I confess to not having read everything, so
  please correct any misapprehensions).  My sense is that the technique
  is oriented towards detecting programmer errors and responding via an
  exception.
 
  I don't think ENFORCE is oriented toward that at all. There's no
orientation
  involved other than to throw an exception based on a condition. I agree
with
  you that direct programming errors should generally not throw exceptions
but
  should ASSERT so that the programmer can fix the error. However I don't
  think ENFORCE has anything to do with this debate about when to ASSERT
and
  when to throw exceptions. Perhaps the examples give the impression which
you
  have

 I think so.

  but I think the problem is just choosing better examples in which
  one would want to throw an exception and not a technical issue as to
  the benefits of using ENFORCE in order to simplify exception
  throwing.

 Can you show me a better example?  This is not a challenge.  Really,
 if this ENFORCE idea is a useful one I want to understand it.

I think something like:

templateclass T
inline T Enforce( T obj, const char* msg ) {
assert( !!obj, msg );
return obj;
}

(also it's const equivalent...not shown)

now you can do the same sort of thing as mentioned in the article

Enforce(cout)  Enforce(MakeWidget())-ToString();

I would think that the compiler could optimize away the Enforce calls with
NDEBUG defined, but when not defined it will catch NULL derefs as the author
intended.

___
Unsubscribe  other changes: http://lists.boost.org/mailman/listinfo.cgi/boost