Boost logo

Boost :

From: Kevlin Henney (kevlin_at_[hidden])
Date: 2000-07-22 13:08:58

In message <[hidden]>, Beman
Dawes <beman_at_[hidden]> writes
>How about something a bit simpler:
> template<bool Pred> struct meta_assert
> { int assertion_failure_in_meta_assert[Pred ? 1 : -1]; };
> template<> struct meta_assert<true> {};
>This actually works for BCC, MWCW, and MSVC compilers. The specialization
>has to be the <true> flavor for some of them. Steve Cleary introduced me
>to the negative subscript trick, IIRCC. Kevlin Henney has used a similar
>(or maybe the same?) technique in other boost postings.

I've used a bunch of different techniques, but with arrays it has tended
to be 0 rather than a -ve number. Problem with 0 is that some compilers
allow this as an array size :-( So -ve numbers are definitely the way to

>The usage inside a generator (where b is a compile time expression
>convertible to bool) is:
> meta_assert< b > use_name_as_error_message_surogate;
>It could also be used as a base class, but I haven't tested that.

Would perhaps be better if reworked to ensure that it was an empty base
class. Can't remember, did we try statics, typedefs, etc?

>Would this be sufficient for template metaprogramming?

This looks good, and the name works for me.

  Kevlin Henney phone: +44 117 942 2990
  Curbralan Ltd mobile: +44 7801 073 508
  kevlin_at_[hidden] fax: +44 870 052 2289

Boost list run by bdawes at, gregod at, cpdaniel at, john at