How to fix this compilation error for comparing std :: chrono in C ++ 11?

I follow the example of an ASIO server with a timeout , and the line with the function shown here was changed from deadline_timer :: traits_type :: now () to be std :: chrono :: stable_clock :: now (), because I wanted to use standalone ASIO without boost. ASIO can use standalone with C ++ 11.

void check_deadline(deadline_timer* deadline)
{
    if (stopped())
      return;

    // Check whether the deadline has passed. compare the deadline against
    // the current time 
    // I modified this to be std::chrono::steady_clock::now()
    if (deadline->expires_at() <= deadline_timer::traits_type::now())         {
      // deadline is asio::high_resolution_time type
      stop();
    } else {
      // Put the actor back to sleep.
      deadline->async_wait(
          std::bind(&TCP_Session::check_deadline, shared_from_this(), deadline));    
    }
  }

Problem

In VS2015, the compiler works, but in Eclipse g ++ 4.9.2 it complains about

no match for 'operator<=' (operand types are 
'asio::basic_waitable_timer<std::chrono::_V2::system_clock>::time_point 

aka 
std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long long int, std::ratio<1ll, 1000000000ll> > >}'

 and 

'std::chrono::_V2::steady_clock::time_point {aka std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long long int, std::ratio<1ll, 1000000000ll> > >}')  TCPSession.h    line 284    C/C++ Problem

Question:

I found that I can only use C ++ 11, not C ++ 14. So, how to fix this in C ++ 11 (without boost or classic unix C)?

+4
source share
2 answers

ASIO deadline timer ASIO. , , , asio::steady_timer .

"" "":

#ifdef ASIO_STANDALONE
  #include <asio.hpp>
  #define ASIO asio
  #define ASIO_ERROR_CODE asio::error_code
  #define ASIO_TIMER asio::steady_timer
#else
  #include <boost/asio.hpp>
  #define ASIO boost::asio
  #define ASIO_ERROR_CODE boost::system::error_code
  #define ASIO_TIMER boost::asio::deadline_timer
#endif
+4

, Boost Asio std::chrono, (, , , ).

, , , , asio::high_resolution_timer. , .

, deadline.

0

Source: https://habr.com/ru/post/1625236/


All Articles