Reputation: 105
I'm new to C++, especially templates. I'm trying to use bind to an overloaded template function - the actual function is serial_port::set_option. For now i have reached the following form:
auto f = std::bind(static_cast<boost::system::error_code(serial_port::*)
(const SettableSerialPortOption&,boost::system::error_code&)>
(&serial_port::set_option),sp_ptr,_1,ec);
with sp_ptr defined as:
std::shared_ptr<serial_port> sp_ptr;
the overloaded method definition is:
template<
typename SettableSerialPortOption>
boost::system::error_code set_option(
const SettableSerialPortOption & option,
boost::system::error_code & ec);
My intention is to get a call like:
f(boost::asio::serial_port::baud_rate(9600));
to work. I have no idea where to define the name SettableSerialPortOption
. Can you provide some help on this?
Upvotes: 2
Views: 273
Reputation: 105
Update: I was able to do it with:
auto &local_ptr = sp_ptr;
auto f = [local_ptr,&ec] (auto&& a){local_ptr>set_option(decltype(a)a,ec);};
f(baud_rate);
Thanks to Piotr Skotnicki for the solution. (perfect forwarding) Thanks to Yakk, I need to read about this, it's getting quite technical for me, but for other users and future reference apparently this is the way to go.
Upvotes: 2