Boost logo

Boost :

From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2001-11-24 13:28:34


Andrei Alexandrescu wrote:
> > The above STATIC_ASSERT_MSG macro can only be used in
> > function scope which highly limits its use. IMHO, an industry
> > strength STATIC_CHECK must be usable at:
> > - namespace,
> > - class, and
> > - function scope.
>
> I know. The current STATIC_ASSERT has the same drawback.

It doesn't. From http://www.boost.org/libs/static_assert/static_assert.htm:
"Note that if the condition is true, then the macro will generate neither
code nor data - and the macro can also be used at either namespace, class or
function scope. When used in a template, the static assertion will be
evaluated at the time the template is instantiated; this is particularly
useful for validating template parameters."

> > So, use "do {...} while (0)" instead of "{ ... }".
>
> I thought this is self-understood as it is a well-known idiom
> for creating macros. I was actually surprised to see that boost doesn't
> apply this idiom all over, and I was going to complain about that.
>
> So by this message I am complaining :o).

The idiom is not used in BOOST_STATIC_ASSERT because it would limit the
macro applicability to one particular scope.

--
Aleksey

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk