Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards



BOOST_WARN_MESSAGE(predicate, message);
BOOST_CHECK_MESSAGE(predicate, message);
BOOST_REQUIRE_MESSAGE(predicate, message);

These tools perform exactly the same check as BOOST_<level> tools. The only difference is that instead of generating an error/confirm message these use the supplied one.

The first parameter is the boolean expression. The second parameter is the message reported in case of check failure. The message argument can be constructed of components of any type supporting the std::ostream& operator<<(std::ostream&).

Example: BOOST_<level>_MESSAGE usage


#define BOOST_TEST_MODULE example
#include <boost/test/included/unit_test.hpp>

#include <cmath>

  // sin 45 radians is actually ~ 0.85, sin 45 degrees is ~0.707
  double res = std::sin( 45. );

  BOOST_WARN_MESSAGE( res < 0.71,
                      "sin(45){" << res << "} is > 0.71. Arg is not in radian?" );


> example --log_level=warning
Running 1 test case...
test.cpp(12): warning in "test": sin(45){0.850904} is > 0.71. Arg is not in radian?

*** No errors detected

See also: