|
Boost : |
From: Jeremy Siek (jsiek_at_[hidden])
Date: 2000-12-15 11:28:44
Why not assert()? I don't know... its so... old school ;) And
std::range_error is just itching to get used.
Just for fun, here's an alternate definition that's more useful when
debuging (at least in gdb). Stops execution (via a seg fault) and lets you
see the current environment, stack, etc.
#define BOOST_ASSERT_RANGE(expr) \
do if (!expr) { \
int* x = 0; \
*x = 0; \
} while (0)
On Fri, 15 Dec 2000, DEAN STURTEVANT wrote:
dean> --- In boost_at_[hidden], Jeremy Siek <jsiek_at_l...> wrote:
dean> > Should we have a boost macro for adding in this kind of assertion?
dean> >
dean> > #define BOOST_ASSERT_RANGE(expr) \
dean> > if (expr) \
dean> > throw std::range_error( \
dean> > __FILE__ + std::string(":") \
dean> > + boost::lexical_cast<std::string>(__LINE__) + \
dean> > std::string(": range error") )
dean> >
dean>
dean> Well, ignoring the fact that the test should be on !(expr) rather
dean> than expr and that the construction is syntactically incorrect (You
dean> can't go "string" + std::string("str")), I was thinking of something
dean> more lightweight. What is wrong with assert()?
dean>
dean>
dean>
dean>
dean>
dean>
----------------------------------------------------------------------
Jeremy Siek www: http://www.lsc.nd.edu/~jsiek/
Ph.D. Candidate email: jsiek_at_[hidden]
Univ. of Notre Dame work phone: (219) 631-3906
----------------------------------------------------------------------
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk