如何在没有提升deadline_timer的情况下将boost :: asio代码完全转换为C++ 11/asio?

Spl*_*ash 3 c++ boost boost-asio c++11

我的目标是让我的项目使用没有Boost 的" asio "库,但使用C++ 11.示例是将此服务器代码转换为使用Timeout.

这是我做的:

  1. boost::bind- > std::bind,_1- >std::placeholders::_1
  2. 大多数boost::asio::xxx- >asio::xxx
  3. boost::system::error_code - > asio::error_code

现在,deadline_timer还有12个错误:

deadline_timer input_deadline_;
input_deadline_.expires_at(boost::posix_time::pos_infin);
...
void check_deadline(deadline_timer* deadline)
{
    ...

    if (deadline->expires_at() <= deadline_timer::traits_type::now())
Run Code Online (Sandbox Code Playgroud)

什么是正确的代码使用?我正在使用GCC 4.9.1/2,并且新下载了asio库1.10.6.

seh*_*ehe 6

您可以使用high_resolution_timer,它std::chrono在C++ 11编译器上使用:

#if defined(GENERATING_DOCUMENTATION)
/// Typedef for a timer based on the high resolution clock.
/**
 * This typedef uses the C++11 @c &lt;chrono&gt; standard library facility, if
 * available. Otherwise, it may use the Boost.Chrono library. To explicitly
 * utilise Boost.Chrono, use the basic_waitable_timer template directly:
 * @code
 * typedef basic_waitable_timer<boost::chrono::high_resolution_clock> timer;
 * @endcode
 */
typedef basic_waitable_timer<
    chrono::high_resolution_clock>
  high_resolution_timer;
#elif defined(ASIO_HAS_STD_CHRONO)
typedef basic_waitable_timer<
    std::chrono::high_resolution_clock>
  high_resolution_timer;
#elif defined(ASIO_HAS_BOOST_CHRONO)
typedef basic_waitable_timer<
    boost::chrono::high_resolution_clock>
  high_resolution_timer;
#endif

} // namespace asio
Run Code Online (Sandbox Code Playgroud)