简体   繁体   中英

C++11 type deduce with asio

I am using boost::asio::steady_timer _timer , but I found if using -std=c++11 flag, compiler will report error of can not convert type at:

boost::asio::steady_timer::time_point now() {
    return boost::asio::steady_timer::clock_type::now();
}

and no match function for operator+() at:

_timer.expires_at(now()+boost::chrono::milliseconds(100));

It seems the compiler can not deduce the correct type in c++11 mode. But instead I using

boost::asio::basic_waitable_timer<boost::chrono::steady_clock> _timer;

and change boost::asio::steady_timer::time_point to boost::chrono::steady_clock::time_point

It is OK. However, they are same thing and work fine in g++ without 0x or 11 mode.

Is C++11 do something different thing about typedef deduce? Or a boost config problem?

The basic_waitable_timer class can work with std::chrono or boost::chrono . On a recent g++, it uses std::chrono by default. To force using boost::chrono , define BOOST_ASIO_DISABLE_STD_CHRONO .

This is documented here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM