I'm trying to do something like that:
#define VERIFY_EXPECTATIONS \
BOOST_MPL_ASSERT((expectation1)); \
BOOST_MPL_ASSERT((expectation2)); \
BOOST_MPL_ASSERT((expectation3))
and when writing VERIFY_EXPECTATIONS;
in line, say 42, I get an error about a conflicting declaration of mpl_assertion_in_line_42
.
I understand what is happening (BOOST_MPL_ASSERT
uses an identifier that depends on the line where the macro is invoked) but my question is: is there a known workaround to do this kind of things?
Edit:
More precisely, the expectations look like that:
#define TEST_SOME_SET_OF_PREDICATES(Arg) \
BOOST_MPL_ASSERT ((some_predicate<Arg>)); \
BOOST_MPL_ASSERT_NOT((some_other_predicate<Arg>))
TEST_SOME_SET_OF_PREDICATES(some_type);
TEST_SOME_SET_OF_PREDICATES(some_other_type);
I have implemented the predicates and I want to test them with several types.
Note:
I'm not very interested in the following:
template <typename Arg>
struct compound_predicate : boost::mpl::and_<
some_predicate<Arg>,
boost::mpl::not_<some_other_predicate<Arg> >
> {};
BOOST_MPL_ASSERT((compound_predicate<some_type>));
BOOST_MPL_ASSERT((compound_predicate<some_other_type>));
because when an assertion fails, we don't know which of the expectations was wrong.
The solution suggested by Praetorian would be the following:
template <typename Arg>
struct expectations {
BOOST_MPL_ASSERT ((some_predicate<Arg>));
BOOST_MPL_ASSERT_NOT((some_other_predicate<Arg>));
};
and then instantiate expectations
with some_type
and some_other_type
. I would have to implement a macro that declares an object of type expectations<Arg>
with a different identifier at each call. It looks a little bit like reimplementing (some part of) static assertions.
Any other ideas?