Boost logo

Boost :

From: Andrei Alexandrescu (andrewalex_at_[hidden])
Date: 2001-11-23 15:24:11


Is there a chance of adding a loki-like macro to static_assert.hpp that
would allow a user-defined message to be (likely) included in the error
message?

The idea is to allow the user to specify an error message in the form of an
identifier.

#define STATIC_ASSERT_MSG(b, msg) \
    { \
        struct msg \
        { \
            msg(::boost::loki::int2type<true>) {} \
        } msg(::boost::loki::int2type<(b) != 0>()); \
    }

Then if you say:

STATIC_ASSERT_MSG(false, This_Will_Appear_In_The_Error_Message);

then it's very likely you will see the actual string
This_Will_Appear_In_The_Error_Message in the compiler output. My compiler
says:

Error : function call
'This_Will_Appear_In_The_Error_Message(boost::loki::int2type<0>)' does not
match
'This_Will_Appear_In_The_Error_Message::This_Will_Appear_In_The_Error_Messag
e(boost::loki::int2type<1>)'
'This_Will_Appear_In_The_Error_Message::This_Will_Appear_In_The_Error_Messag
e(const This_Will_Appear_In_The_Error_Message &)'

As you see, This_Will_Appear_In_The_Error_Message appears quite a number of
times in the output :o).

Andrei


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