【发布时间】:2017-01-12 13:20:34
【问题描述】:
我想编写一些代码来兼容不同的 boost 版本,并希望为给定的 boost 版本使用适当的函数。现在我正在尝试,
#if BOOST_VERSION>105000
#define boost_sleep boost::this_thread::sleep_for
#define millisectime boost::chrono::milliseconds
#define timed_join try_join_for
#else
#define boost_sleep boost::this_thread::sleep
#define millisectime boost::posix_time::milliseconds
#endif
这似乎编译得很好。我在代码中使用它,例如,
// Wait for no reason,
boost_sleep(millisectime(1000));
if( !(workerThread->timed_join(millisectime(1000)) )){
cout << "Not joined on time" << endl;
workerThread->detach();
}
有没有更好/标准的方法来做到这一点?有什么改进的建议吗?
【问题讨论】:
-
顺便说一句:从 C++11 开始,您编写的所有代码都是标准 C++
-
是的,计划是迁移到 C++11,但现在我正在尝试尽可能少地更改代码..!哈哈。 (我仍然需要多索引容器的提升)
标签: c++ boost c-preprocessor