競合するマクロ名をブーストテンプレート関数で解決する最適な方法は何ですか?テンプレート関数boost::chrono::round
とシステムヘッダマクロとブーストテンプレート機能との間の名前の競合を解決するには?
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
紛争: ブースト/ chrono.hppを含めた後、私は、コンパイラのエラーを得ました。
/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)
{
- それは場合、マクロ、私はどちらかでき
#undef
ようです私はパッチをround.hpp - 多分私はparanthesesを使用できますか? macro and member function conflictの答えでは、関数名はカッコ内に入っていますが、これはその定義ではなく関数の使用にあります。それは定義でも機能しますか?
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));
}
ハッハッハ、これはマクロを使わないのが古典的な例のようですが、標準ライブラリには私にはわかりません... – Downvoter
@Downvoter確かに、ライブラリの作者の部分ではかなり破壊されてしまいます「ラウンド」という共通の名前です。 –