Boost logo

Boost :

From: Beman Dawes (beman_at_[hidden])
Date: 2000-07-21 15:04:35


Jeremy wrote:

>I've got mechanisms for "concept checking" that should also work for
>error detecting/reporting in TMP, though some more work may be
>necessary to make it easy to use in TMP.
>
>I've uploaded the file concept_checks.h into the vault (TMPX directory).
>I was going to post this soon anyways :) The file isn't
>boostified yet, but it should be able to serve as food for thought.

Well, it got me going:-)

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.

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 this be sufficient for template metaprogramming?

--Beman


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