Boost logo

Boost :

From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2000-02-15 04:09:14


This didn't seem to work with MSVC^ SP3 but perhaps this is my incompetence.

Would you like to send the complete example file for me to try?

(BTW After a number of tries (only with partial success) at this,
I conclude at the bottom, this is a language problem,
and we need to ask the language revisers to try to improve. It is absurd
for example, that one can declare a const array of fixed size known to the
compiler, and then write a[9999] without getting a squeak.

Thanks

Paul

Dr Paul A. Bristow, hetp Chromatography
4 Victoria Road, Wilmslow, Cheshire SK9 5HN UK
Phone +44 1625 520193 FAX & Voicemail +44 1625 252495
email mailto:pbristow_at_[hidden]

> -----Original Message-----
> From: Gavin Collings [mailto:gcollings_at_[hidden]]
> Sent: Monday, February 14, 2000 2:17 PM
> To: boost_at_[hidden]
> Subject: [boost] Re: Compile time assertions
>
>
> > > (R1) Give an error message *at the line* where the assertion
> > > fails.
> >
> > Highly compiler-dependent! No single implementation is *ever* likely
> to
> > satisfy this requirement! Also, some people want readability...
> > CodeWarrior's error messages are often so dismal that it can be very
> hard to
> > accomplish anything that looks reasonable in this regard. On the up
> side,
> > either class or function templates (I forget which) do give an
> instantiation
> > backtrace when they fail to compile.
>
> Well, here's my effort to improve error messages, at least. It works
> on the principle that a string is an invalid template
> argument, but can
> be contained in a valid expression like charp < "literal" > integer
> (looks like a template instantiation). With macros, an additional
> benefit is that the boolean expression can be passed in as a string to
> enhance the error message - which looks like: -
>
> "compile time assertion failure: file test.h line 373 (i > j)"
>
> I've only tried it on gcc; any feedback on other platforms
> appreciated.
>
> --
> Gavin.
>
>
> template <bool> struct ct_assert
> {
> char * ct_message;
> int val;
> };
>
> template <> struct ct_assert<false>
> {
> template <typename> struct ct_message {};
> };
>
>
> #define require( B ) \
> struct join( ct_check, __LINE__ ) : ct_assert<(B)> \
> { \
> void check() \
> { \
> ct_message < "compile time assertion failure: file " __FILE__ \
> " line " stringize( __LINE__ ) \
> " (" #B ")" > val; \
> } \
> }
>
> #define do_join( X, Y ) X ## Y
> #define join( X, Y ) do_join( X, Y )
> #define do_stringize( X ) #X
> #define stringize( X ) do_stringize( X )
>
>
>
>
> --------------------------------------------------------------
> ----------
> *** Got Questions? Get Answers. Got Answers? Get Paid. ***
> Sign up at Infomarco.com and you can win $30,000 cash or a
> trip to China.
> http://click.egroups.com/1/1251/1/_/9351/_/950537814/
>
> -- Create a poll/survey for your group!
> -- http://www.egroups.com/vote?listname=boost&m=1
>
>
>


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