|
Boost : |
From: Kevlin Henney (kevlin_at_[hidden])
Date: 2000-07-22 13:08:58
In message <4.3.2.7.2.20000721155055.02350d00_at_[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
go.
>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 acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk