I want to turn this call:
timer.async_wait(handler);
into this call:
func(handler);
So I tried using std::bind
:
#include <functional>
#include <boost/asio.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/system/error_code.hpp>
using std::bind;
using std::function;
using boost::asio::io_service;
using boost::asio::steady_timer;
using boost::system::error_code;
int main(int, char**) {
using namespace std::placeholders;
io_service io_s;
steady_timer timer (io_s);
// error
function<void(function<void(const error_code&)>)> bound =
bind(&steady_timer::async_wait, timer, _1);
return 0;
}
But it wont compile! When compiled like this:
g++-4.9 -std=c++11 -Wall -I/usr/local/include -L/usr/local/lib -lboost_system -o bin main.cpp
The error message is this:
main.cpp:22:46: error: no matching function for call to 'bind(<unresolved overloaded function type>, boost::asio::steady_timer&, const std::_Placeholder<1>&)'
bind(&steady_timer::async_wait, timer, _1);
I've tried various things (like casting, template arguments, function objects) but I just can't get it to compile.
I'm using Boost ASIO 1.58 and the documentation says the following:
template<
typename WaitHandler>
void-or-deduced async_wait(
WaitHandler handler);
And here you can see what a WaitHandler is. I don't understand what void-or-deduced
mean but I'm thinking it might be what's giving me a tough time? I've stared at this problem for so long now that I think I've gotten tunnel vision.
How do I properly use std::bind
in this case?
Aucun commentaire:
Enregistrer un commentaire