Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2006-11-08 04:53:39


Johan Paulsson wrote:
> I wrote:
>> Below is the compile-time assert I use.
>> Would it be a useful addition to Boost?
>
> To make it easier to digest, I put together a minimal web page with
> - Source code
> - A test
> - Compiler errors from the test, using different compilers (It's
> supposed to make compiler errors). Compiler errors from the same test
> using BOOST_STATIC_ASSERT, BOOST_MPL_ASSERT and BOOST_MPL_ASSERT_MSG
> is
> also included, to make it easy to compare.
>
> I think the benefits of my compile time assert is:
> - No macros
> - No compiler-specific implementation
> - It's easy to make useful error-messages
>
> Please have a look at <http://www.kuodo.com/code/assert/readme.html>
>
> Or download it (12kb) <http://www.kuodo.com/code/assert/assert.zip>

Frankly it's hard to choose between them on error message quality (which is
to say none are all that good).

One of the requirements that came up for static asserts when
BOOST_STATIC_ASSERT was talked about was a declaration like syntax, in fact
both:

static_assert<condition> x;

and

typedef static_assert<condition> x;

were explicitly rejected at the time.

I also seem to remember that some compilers at the time evaluated typedefs
in a lazy manner: if the typedef was unused then it was never evaluated and
the static-assertion was never triggered. That's the reason for some of the
convolutions inside static_assert.hpp. I suspect, however, that current
compilers have moved away from such "lazyness".

And finally, I hope that native static assertions will make it into
compilers soon (they're in the C++ std working draft), when that happens it
would be trivial to redefine macro based solutions to use the native
version: and that really will produce good error messages one hopes!

John.


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