[geos-devel] assert.h / assert()
Mateusz Łoskot
mateusz at loskot.net
Tue Jan 31 19:02:40 EST 2006
Artem Pavlenko wrote:
> Stephen,
>
> GEOS is a c++ library, right? Please see [Stroustrup94],[Stroustrup00]
> on the topic 'Why to avoid macros when possible'.
Yup, macros are not recommended besides those defined by C++ Standard.
Together with macros, it's possible to set permanent assertions that do
not depends on NDEBUG definition.
template <class E, class A> inline void StaticAssert(A expr)
{
if (!expr)
{
throw E();
}
}
Usage:
class BadPolyException {};
MyPoly p;
// ... construct poly
// and check it
StaticAssert<BadPolyException>(p.IsClosed());
We don't need to catch exception, because it will work just as assert()
macro and program execution will be terminated if StaticAssert return false.
It also can be tweaked to be enabled/disabled by NDEBUG.
Cheers
--
Mateusz Łoskot
http://mateusz.loskot.net
More information about the geos-devel
mailing list