jeudi 22 janvier 2015

Is it possible to pass a statement with a comma into a boost test macro?

As I wanted to unit-test a small class I wrote with boost::test, I discovered that the boost MACRO to CHECK/REQUIRE/.... cannot be use directly if the statement you pass contain a ','.


The following example doesn't compile as the preprocessor reports that macro "BOOST_CHECK_NO_THROW" passed 2 arguments, but takes just 1



BOOST_CHECK_NO_THROW({cache_map<int, int> test1(3);});


Just to confirm it comes from the comma we use to separate the template parameters, I used the following and it compiled without issue.



BOOST_CHECK_NO_THROW({string test1("test");});


A work-around is to use a typedefalias instead of the explicit type but have you another idea ?


Aucun commentaire:

Enregistrer un commentaire