Boost logo

Boost :

Subject: [boost] [mpl] ASSERT and other macros using unique IDs
From: lcaminiti (lorcaminiti_at_[hidden])
Date: 2012-02-26 18:38:10

Hello all,

Currently BOOST_MPL_ASSERT_MSG cannot be expanded multiple times on the same
line because (on GCC and alike) it uses __LINE__ to generate unique IDs. I
have to program a macro that makes a bunch of static assertions when it
expands so all these assertions made using BOOST_MPL_ASSERT_MSG are on the
same line. I used BOOST_MPL_ASSERT_MSG_IMPL to pass the unique ID directly
(which is generated by concatenating __LINE__ with the assertion counter
which my macro keeps). However, this is not an ideal solution because
BOOST_MPL_ASSERT_MSG_IMPL is part of a private API and it could change in
the future.

Is there any interest in making BOOST_MPL_ASSERT_IMPL part of the public
API? (So I can directly pass the unique ID to use. I'd be best if the unique
ID is not required to be numeric but just a concatenable token.)

I had a similar issue with Boost.Concet's REQUIRES.

#define CONTRACT_AUX_MPL_ASSERT_MSG_(counter, condition, message, types) \
    /* unfortunately, need to use Boost.MPL implementation detail */ \
    /* to pass unique ID (not just __LINE__) so this macro can be expanded
*/ \
    /* multiple times on the same line if with different IDs */ \
            BOOST_PP_CAT(BOOST_PP_CAT(message, _id_), counter), \
            condition, message, types)

// PUBLIC //

// Allow to expand multiple assert macros on same line (without name
#define CONTRACT_AUX_MPL_ASSERT_MSG(condition, message, types) \
            BOOST_MPL_AUX_PP_COUNTER(), /* uses Boost.MPL impl detail */ \
            condition, message, types)


View this message in context:
Sent from the Boost - Dev mailing list archive at

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