What is the best way to resolve a conflicting macro name with a boost template function? After including boost/chrono.hpp I got the compiler error:
CCN5816 (W) Too many arguments are specified for the macro "round". The extra arguments are ignored. "/usr/include/math.h", line 2133.16: CCN5425 (I) "round" is defined on line 2133 of "/usr/include/math.h".
round
conflicts with the template function boost::chrono::round
.
/usr/include/math.h
#define round(x) __round(x)
/boost/chrono/round.hpp
namespace boost
{
namespace chrono
{
/**
* rounds to nearest, to even on tie
*/
template <class To, class Rep, class Period>
To round(const duration<Rep, Period>& d)
{
- It seems that I can either
#undef
the macro if I patch round.hpp - Maybe I can use parantheses? In the answer to macro and member function conflict the function name is within parentheses but this is in the usage of the function, not in its definition. Would it work in the definition too?
BoostChronoTest.cpp
#include <gtest/gtest.h>
#include <boost/chrono.hpp>
TEST(BoostChronoTest, simpleTests) {
boost::chrono::nanoseconds ns(12000);
// conversion with precision loss requires a cast
boost::chrono::microseconds ms = boost::chrono::duration_cast<boost::chrono::microseconds>(ns);
// no precision loss
boost::chrono::nanoseconds ns2 = ms;
ms++;
ms += boost::chrono::duration_cast<boost::chrono::microseconds>(ns);
ns *= 2;
EXPECT_TRUE(ms > ns);
EXPECT_EQ(ms, boost::chrono::microseconds(25));
EXPECT_EQ(ns, boost::chrono::nanoseconds(24000));
EXPECT_EQ(ns2, boost::chrono::microseconds(12));
EXPECT_EQ(ns2, boost::chrono::nanoseconds(12000));
}