|
Boost Users : |
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2007-07-24 09:04:50
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
> <boost/utility.hpp>.
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
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