
Hello!
I don't sure, that I choose right mail list for my ofer... So, don't
beat me much... :)
I often use such macro for testing function parameters:
#define THROW_INVALID_ARGUMENT_IF_FAIL(expression) \
do { \
using std::invalid_argument; \
using std::string; \
\
if(!(expression)) \
throw invalid_argument(string(BOOST_CURRENT_FUNCTION) + \
" : Assertion '" #expression "' failed"); \
} while(false)
I think, that this macro is very useful and can be part of

On Tue, July 24, 2007 14:41, Pavel Syomin wrote:
Hello!
I don't sure, that I choose right mail list for my ofer... So, don't beat me much... :) I often use such macro for testing function parameters:
#define THROW_INVALID_ARGUMENT_IF_FAIL(expression) \ do { \ using std::invalid_argument; \ using std::string; \ \ if(!(expression)) \ throw invalid_argument(string(BOOST_CURRENT_FUNCTION) + \ " : Assertion '" #expression "' failed"); \ } while(false)
I think, that this macro is very useful and can be part of
.
Hi! Just a question: why do you need the do-while loop if this thing iterates anyway only once? You can define a new scope without do and while: #define THROW_INVALID_ARGUMENT_IF_FAIL(expression) \ { \ using std::invalid_argument; \ using std::string; \ \ if(!(expression)) \ throw invalid_argument(string(BOOST_CURRENT_FUNCTION) + \ " : Assertion '" #expression "' failed"); \ } My opinion would be to integrate the kind of macro (if it is really required) to boost::exception code if this is going to be accepted in the review (which will hopefully start soon). With Kind Regards, Ovanes

On Tue, Jul 24, 2007 at 03:04:50PM +0200, Ovanes Markarian wrote:
Just a question: why do you need the do-while loop if this thing iterates anyway only once? You can define a new scope without do and while:
That's in the C FAQ: http://c-faq.com/cpp/multistmt.html Without do/while, the following code wouldn't compile: if(x) THROW(x+1 == 0); else THROW(x == 7); The macro name is definetly too long, i couldn't force myself to write it even for this simple illustration.

On Tue, Jul 24, 2007 at 05:36:46PM +0400, Pavel Syomin wrote:
Hi!
The macro name is definetly too long, i couldn't force myself to write it even for this simple illustration.
Yes, I agree with you, that macro name is to long. Another name can be, for example, BOOST_CHECK_CONTRACT().
So what is wrong with assert()?

Hi, A few comments: 1) The macro may be of a very limited usage, as comma inside will break it. Preprocessor will choke on this: THROW_INVALID_ARGUMENT_IF_FAIL( my_func( a, b, c ) ); 2) Could the name be just BOOST_THROW_IF_FAILED (still too long)? 3) Might it not be nice to have a variant that would also take exception type as an argument? Best regards, Vsevolod Vlaskine ____________________________________________________________________________________ Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase. http://farechase.yahoo.com/

On Wed, July 25, 2007 02:54, Vsevolod Vlaskin wrote:
Hi,
A few comments:
1) The macro may be of a very limited usage, as comma inside will break it. Preprocessor will choke on this:
THROW_INVALID_ARGUMENT_IF_FAIL( my_func( a, b, c ) );
Comma is not a real threat. This macro will compile fine: THROW_INVALID_ARGUMENT_IF_FAIL( (my_func( a, b, c )) ); [...] But the article written by Andrei Alexandrescu (see some posts before) seams to be really great and much better as the current suggestion. With Kind Regards, Ovanes Markarian

Pavel Syomin wrote:
Hello!
I don't sure, that I choose right mail list for my ofer... So, don't beat me much... :) I often use such macro for testing function parameters:
#define THROW_INVALID_ARGUMENT_IF_FAIL(expression) \ do { \ using std::invalid_argument; \ using std::string; \ \ if(!(expression)) \ throw invalid_argument(string(BOOST_CURRENT_FUNCTION) + \ " : Assertion '" #expression "' failed"); \ } while(false)
I think, that this macro is very useful and can be part of
.
see Andrei Alexandrescu and Petru Marginean's article 'Enforcements' http://www.ddj.com/dept/cpp/184403864

Hi!
see Andrei Alexandrescu and Petru Marginean's article 'Enforcements' http://www.ddj.com/dept/cpp/184403864
Thank you very much! I think, that the better name for this macro is BOOST_ENFORCE().

Hi all! New variant of BOOST_ENFORCE macro: #define BOOST_ENFORCE(expression) \ do { \ if(!(expression)) throw std::invalid_argument( \ __FILE__ " : " BOOST_STRINGIZE(__LINE__) " : " \ + std::string(BOOST_CURRENT_FUNCTION) + \ " : Expression '" #expression "' failed"); \ } while(false) And few question about it: 1. How to escape converting BOOST_CURRENT_FUNCTION to std::string? Is there way to get function name as string literal? 2. Is line number useful information? I think, that filename and function name is good enough. 3. Any observations and suggestions?

Pavel Syomin wrote:
1. How to escape converting BOOST_CURRENT_FUNCTION to std::string? Is there way to get function name as string literal?
Some compilers support __FUNCTION__ macro.
Thanks,
Boris
----- Original Message -----
From: "Pavel Syomin"
Hi all! New variant of BOOST_ENFORCE macro:
#define BOOST_ENFORCE(expression) \ do { \ if(!(expression)) throw std::invalid_argument( \ __FILE__ " : " BOOST_STRINGIZE(__LINE__) " : " \ + std::string(BOOST_CURRENT_FUNCTION) + \ " : Expression '" #expression "' failed"); \ } while(false)
And few question about it: 1. How to escape converting BOOST_CURRENT_FUNCTION to std::string? Is there way to get function name as string literal? 2. Is line number useful information? I think, that filename and function name is good enough. 3. Any observations and suggestions? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Hi, Am 25.07.2007 um 14:51 schrieb Boris Gubenko:
Pavel Syomin wrote:
1. How to escape converting BOOST_CURRENT_FUNCTION to std::string? Is there way to get function name as string literal?
Some compilers support __FUNCTION__ macro.
Thanks, Boris
as far as I know, for GNU compilers __func__ is part of the C99 standard. Older versions recognize only __FUNCTION__, but it is not standardized. For better portability the following provides a fallback definition with the preprocessor: #if __STDC_VERSION__ < 199901L #if __GNUC__ >= 2 #define __func__ __FUNCTION__ #else #error "function name variable is not defined" #endif #endif ... and in C++ there is PRETTY_FUNCTION, e.g. "void a::foo(int)" instead of "foo". Greetings Klaus

on Tue Jul 24 2007, Pavel Syomin
Hello!
I don't sure, that I choose right mail list for my ofer... So, don't beat me much... :) I often use such macro for testing function parameters:
#define THROW_INVALID_ARGUMENT_IF_FAIL(expression) \ do { \ using std::invalid_argument; \ using std::string; \ \ if(!(expression)) \ throw invalid_argument(string(BOOST_CURRENT_FUNCTION) + \ " : Assertion '" #expression "' failed"); \ } while(false)
I think, that this macro is very useful and can be part of
.
I don't think we should include facilities that encourage responding to precondition violations with exceptions. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com

Hi!
I don't think we should include facilities that encourage responding to precondition violations with exceptions.
Why do you think that using exceptions for notifying about precondition violation is a bad practice? I think, that ASSERT is a much narrow approach because of program termination.

on Sun Jul 29 2007, Pavel Syomin
Hi!
I don't think we should include facilities that encourage responding to precondition violations with exceptions.
Why do you think that using exceptions for notifying about precondition violation is a bad practice? I think, that ASSERT is a much narrow approach because of program termination.
See my posts in http://tinyurl.com/2x5f4c -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com
participants (8)
-
Boris Gubenko
-
David Abrahams
-
Ilya Sokolov
-
Klaus Backert
-
Ovanes Markarian
-
Pavel Syomin
-
Vsevolod Vlaskin
-
Zeljko Vrba