|
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_MPL_ASSERT_MSG_IMPL( \
BOOST_PP_CAT(BOOST_PP_CAT(message, _id_), counter), \
condition, message, types)
// PUBLIC //
// Allow to expand multiple assert macros on same line (without name
clashes).
#define CONTRACT_AUX_MPL_ASSERT_MSG(condition, message, types) \
CONTRACT_AUX_MPL_ASSERT_MSG_( \
BOOST_MPL_AUX_PP_COUNTER(), /* uses Boost.MPL impl detail */ \
condition, message, types)
Thanks.
--Lorenzo
-- View this message in context: http://boost.2283326.n4.nabble.com/boost-mpl-ASSERT-and-other-macros-using-unique-IDs-tp4423225p4423225.html Sent from the Boost - Dev mailing list archive at Nabble.com.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk