Compiler error boost::asio::placeholder::error with boost v1.69 - c++

The following code compiles and runs with the expected results ( 'done' on console after 3 seconds ) when build in codeblocks v17 with 32 bit g++ v5.1 and boost v1.63
#include <iostream>
#include <thread>
#include <boost/bind.hpp>
#include <boost/asio.hpp>
namespace pinmed
{
class cTimedEvent
{
public:
cTimedEvent( boost::asio::io_service& ios )
: myTimer( ios )
{
}
/** Schedule one-off timed event
#param[in] msecs delay from now
#param[in] handler to call when delay expires
*/
template<
typename H >
void Schedule(
int msecs,
H handler )
{
myTimer.expires_from_now(
boost::posix_time::milliseconds( msecs ));
myTimer.async_wait( handler );
}
private:
boost::asio::deadline_timer myTimer;
};
class cClass
{
public:
cClass( boost::asio::io_service& ios )
: myTimedEvent( ios )
{
myTimedEvent.Schedule(
3000,
boost::bind(
&cClass::handler,
this,
boost::asio::placeholders::error) );
}
void handler(
const boost::system::system_error& e)
{
std::cout << "done\n";
}
private:
cTimedEvent myTimedEvent;
};
}
using namespace std;
int main()
{
boost::asio::io_service ios;
pinmed::cClass theClass( ios );
ios.run();
return 0;
}
However, when I "upgrade" to 64 bit g++ v8.2 with boost v1.69 then I get a horrible compiler error:
-------------- Build: Debug in test_timed (compiler: GNU GCC Compiler)---------------
g++.exe -Wall -fexceptions -g -std=c++11 -IC:\Users\James\code\boost\boost_1_69_0 -c C:\Users\James\code\test_timed\main.cpp -o obj\Debug\main.o
g++.exe -LC:\Users\James\code\boost\v1_63_gcc51\stage\lib -LC:\Users\James\code\nana-1.6.2\build\codeblocks -o \bin\test_timed.exe obj\Debug\main.o -lboost_thread-mgw51-mt-1_63 -lboost_system-mgw51-mt-1_63 -lboost_program_options-mgw51-mt-1_63 -lboost_filesystem-mgw51-mt-1_63 -lws2_32
In file included from C:\Users\James\code\boost\boost_1_69_0/boost/bind.hpp:22,
from C:\Users\James\code\test_timed\main.cpp:3:
C:\Users\James\code\boost\boost_1_69_0/boost/bind/bind.hpp: In instantiation of 'void boost::_bi::list2<A1, A2>::operator()(boost::_bi::type<void>, F&, A&, int) [with F = boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>; A = boost::_bi::rrlist1<const boost::system::error_code&>; A1 = boost::_bi::value<pinmed::cClass*>; A2 = boost::arg<1> (*)()]':
C:\Users\James\code\boost\boost_1_69_0/boost/bind/bind.hpp:1306:50: required from 'boost::_bi::bind_t<R, F, L>::result_type boost::_bi::bind_t<R, F, L>::operator()(A1&&) [with A1 = const boost::system::error_code&; R = void; F = boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>; L = boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()>; boost::_bi::bind_t<R, F, L>::result_type = void]'
C:\Users\James\code\boost\boost_1_69_0/boost/asio/detail/bind_handler.hpp:65:5: required from 'void boost::asio::detail::binder1<Handler, Arg1>::operator()() [with Handler = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >; Arg1 = boost::system::error_code]'
C:\Users\James\code\boost\boost_1_69_0/boost/asio/handler_invoke_hook.hpp:69:11: required from 'void boost::asio::asio_handler_invoke(Function&, ...) [with Function = boost::asio::detail::binder1<boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >, boost::system::error_code>]'
C:\Users\James\code\boost\boost_1_69_0/boost/asio/detail/handler_invoke_helpers.hpp:37:22: required from 'void boost_asio_handler_invoke_helpers::invoke(Function&, Context&) [with Function = boost::asio::detail::binder1<boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >, boost::system::error_code>; Context = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >]'
C:\Users\James\code\boost\boost_1_69_0/boost/asio/detail/handler_work.hpp:82:46: required from 'void boost::asio::detail::handler_work<Handler, boost::asio::system_executor>::complete(Function&, Handler&) [with Function = boost::asio::detail::binder1<boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >, boost::system::error_code>; Handler = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >]'
C:\Users\James\code\boost\boost_1_69_0/boost/asio/detail/wait_handler.hpp:72:7: required from 'static void boost::asio::detail::wait_handler<Handler>::do_complete(void*, boost::asio::detail::operation*, const boost::system::error_code&, std::size_t) [with Handler = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >; boost::asio::detail::operation = boost::asio::detail::win_iocp_operation; std::size_t = long long unsigned int]'
C:\Users\James\code\boost\boost_1_69_0/boost/asio/detail/wait_handler.hpp:39:15: required from 'boost::asio::detail::wait_handler<Handler>::wait_handler(Handler&) [with Handler = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >]'
C:\Users\James\code\boost\boost_1_69_0/boost/asio/detail/deadline_timer_service.hpp:236:11: required from 'void boost::asio::detail::deadline_timer_service<Time_Traits>::async_wait(boost::asio::detail::deadline_timer_service<Time_Traits>::implementation_type&, Handler&) [with Handler = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >; Time_Traits = boost::asio::time_traits<boost::posix_time::ptime>]'
C:\Users\James\code\boost\boost_1_69_0/boost/asio/basic_deadline_timer.hpp:610:5: required from 'typename boost::asio::async_result<typename std::decay<_U1>::type, void(boost::system::error_code)>::return_type boost::asio::basic_deadline_timer<Time, TimeTraits>::async_wait(WaitHandler&&) [with WaitHandler = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >&; Time = boost::posix_time::ptime; TimeTraits = boost::asio::time_traits<boost::posix_time::ptime>; typename boost::asio::async_result<typename std::decay<_U1>::type, void(boost::system::error_code)>::return_type = void]'
C:\Users\James\code\test_timed\main.cpp:31:9: required from 'void pinmed::cTimedEvent::Schedule(int, H) [with H = boost::_bi::bind_t<void, boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>, boost::_bi::list2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()> >]'
C:\Users\James\code\test_timed\main.cpp:49:51: required from here
C:\Users\James\code\boost\boost_1_69_0/boost/bind/bind.hpp:319:35: error: no match for call to '(boost::_mfi::mf1<void, pinmed::cClass, const boost::system::system_error&>) (pinmed::cClass*&, const boost::system::error_code&)'
unwrapper<F>::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]);
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn.hpp:215,
from C:\Users\James\code\boost\boost_1_69_0/boost/mem_fn.hpp:22,
from C:\Users\James\code\boost\boost_1_69_0/boost/bind/bind.hpp:26,
from C:\Users\James\code\boost\boost_1_69_0/boost/bind.hpp:22,
from C:\Users\James\code\test_timed\main.cpp:3:
C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn_template.hpp:163:7: note: candidate: 'R boost::_mfi::mf1<R, T, A1>::operator()(T*, A1) const [with R = void; T = pinmed::cClass; A1 = const boost::system::system_error&]'
R operator()(T * p, A1 a1) const
^~~~~~~~
C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn_template.hpp:163:7: note: no known conversion for argument 2 from 'const boost::system::error_code' to 'const boost::system::system_error&'
C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn_template.hpp:168:25: note: candidate: 'template<class U> R boost::_mfi::mf1<R, T, A1>::operator()(U&, A1) const [with U = U; R = void; T = pinmed::cClass; A1 = const boost::system::system_error&]'
template<class U> R operator()(U & u, A1 a1) const
^~~~~~~~
C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn_template.hpp:168:25: note: template argument deduction/substitution failed:
In file included from C:\Users\James\code\boost\boost_1_69_0/boost/bind.hpp:22,
from C:\Users\James\code\test_timed\main.cpp:3:
C:\Users\James\code\boost\boost_1_69_0/boost/bind/bind.hpp:319:35: note: cannot convert '(& a)->boost::_bi::rrlist1<const boost::system::error_code&>::operator[](boost::_bi::storage2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()>::a2_)' (type 'const boost::system::error_code') to type 'const boost::system::system_error&'
unwrapper<F>::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]);
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn.hpp:215,
from C:\Users\James\code\boost\boost_1_69_0/boost/mem_fn.hpp:22,
from C:\Users\James\code\boost\boost_1_69_0/boost/bind/bind.hpp:26,
from C:\Users\James\code\boost\boost_1_69_0/boost/bind.hpp:22,
from C:\Users\James\code\test_timed\main.cpp:3:
C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn_template.hpp:176:25: note: candidate: 'template<class U> R boost::_mfi::mf1<R, T, A1>::operator()(const U&, A1) const [with U = U; R = void; T = pinmed::cClass; A1 = const boost::system::system_error&]'
template<class U> R operator()(U const & u, A1 a1) const
^~~~~~~~
C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn_template.hpp:176:25: note: template argument deduction/substitution failed:
In file included from C:\Users\James\code\boost\boost_1_69_0/boost/bind.hpp:22,
from C:\Users\James\code\test_timed\main.cpp:3:
C:\Users\James\code\boost\boost_1_69_0/boost/bind/bind.hpp:319:35: note: cannot convert '(& a)->boost::_bi::rrlist1<const boost::system::error_code&>::operator[](boost::_bi::storage2<boost::_bi::value<pinmed::cClass*>, boost::arg<1> (*)()>::a2_)' (type 'const boost::system::error_code') to type 'const boost::system::system_error&'
unwrapper<F>::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]);
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn.hpp:215,
from C:\Users\James\code\boost\boost_1_69_0/boost/mem_fn.hpp:22,
from C:\Users\James\code\boost\boost_1_69_0/boost/bind/bind.hpp:26,
from C:\Users\James\code\boost\boost_1_69_0/boost/bind.hpp:22,
from C:\Users\James\code\test_timed\main.cpp:3:
C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn_template.hpp:184:7: note: candidate: 'R boost::_mfi::mf1<R, T, A1>::operator()(T&, A1) const [with R = void; T = pinmed::cClass; A1 = const boost::system::system_error&]'
R operator()(T & t, A1 a1) const
^~~~~~~~
C:\Users\James\code\boost\boost_1_69_0/boost/bind/mem_fn_template.hpp:184:7: note: no known conversion for argument 1 from 'pinmed::cClass*' to 'pinmed::cClass&'
Process terminated with status 1 (0 minute(s), 8 second(s))
1 error(s), 12 warning(s) (0 minute(s), 8 second(s))

What is the signature of handler of deadline_timer::async_wait method?
According to reference it is:
void handler(
const boost::system::error_code& error // Result of operation.
);
What is your signature?
void handler(
const boost::system::system_error& e)
{
std::cout << "done\n";
}
Change your handler to:
void handler(
const boost::system::error_code& e)
{
std::cout << "done\n";
}

Related

Catkin build fails when a lambda is added to it

rand_dat1_sub_handle = node.subscribe<geometry_msgs::Vector3>(
"random/data1", 100,
[](geometry_msgs::Vector3::ConstPtr& data){std::cout<<data->x;});
rand_dat2_sub_handle = node.subscribe<geometry_msgs::Vector3>(
"random/data2", 100,
[](geometry_msgs::Vector3::ConstPtr& data){std::cout<<data->x;});
when I use the above block of code in my class definition script, my build fails giving me the following errors.
In file included from /usr/include/boost/function/detail/maybe_include.hpp:18:0,
from /usr/include/boost/function/detail/function_iterate.hpp:14,
from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:52,
from /usr/include/boost/function.hpp:64,
from /opt/ros/melodic/include/ros/forwards.h:40,
from /opt/ros/melodic/include/ros/common.h:37,
from /opt/ros/melodic/include/ros/ros.h:43,
from /home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.h:7,
from /home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:2:
/usr/include/boost/function/function_template.hpp: In instantiation of ‘static void boost::detail::function::void_function_obj_invoker1<FunctionObj, R, T0>::invoke(boost::detail::function::function_buffer&, T0) [with FunctionObj = TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>; R = void; T0 = const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&]’:
/usr/include/boost/function/function_template.hpp:925:38: required from ‘void boost::function1<R, T1>::assign_to(Functor) [with Functor = TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>; R = void; T0 = const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&]’
/usr/include/boost/function/function_template.hpp:716:7: required from ‘boost::function1<R, T1>::function1(Functor, typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type) [with Functor = TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>; R = void; T0 = const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&; typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type = int]’
/usr/include/boost/function/function_template.hpp:1061:16: required from ‘boost::function<R(T0)>::function(Functor, typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type) [with Functor = TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>; R = void; T0 = const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&; typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type = int]’
/home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:85:83: required from here
/usr/include/boost/function/function_template.hpp:159:11: error: no match for call to ‘(TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>) (const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&)’
BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
^
/usr/include/boost/function/function_template.hpp:159:11: note: candidate: void (*)(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&) {aka void (*)(boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&)} <conversion>
/usr/include/boost/function/function_template.hpp:159:11: note: conversion of argument 2 would be ill-formed:
/usr/include/boost/function/function_template.hpp:159:11: error: binding reference of type ‘geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr& {aka boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&}’ to ‘const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >’ discards qualifiers
/home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:85:50: note: candidate: TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)> <near match>
[](geometry_msgs::Vector3::ConstPtr& data){std::cout<<data->x<<std::endl;});
^
/home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:85:50: note: conversion of argument 1 would be ill-formed:
In file included from /usr/include/boost/function/detail/maybe_include.hpp:18:0,
from /usr/include/boost/function/detail/function_iterate.hpp:14,
from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:52,
from /usr/include/boost/function.hpp:64,
from /opt/ros/melodic/include/ros/forwards.h:40,
from /opt/ros/melodic/include/ros/common.h:37,
from /opt/ros/melodic/include/ros/ros.h:43,
from /home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.h:7,
from /home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:2:
/usr/include/boost/function/function_template.hpp:159:11: error: binding reference of type ‘geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr& {aka boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&}’ to ‘const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >’ discards qualifiers
BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
^
/usr/include/boost/function/function_template.hpp: In instantiation of ‘static void boost::detail::function::void_function_obj_invoker1<FunctionObj, R, T0>::invoke(boost::detail::function::function_buffer&, T0) [with FunctionObj = TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>; R = void; T0 = const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&]’:
/usr/include/boost/function/function_template.hpp:925:38: required from ‘void boost::function1<R, T1>::assign_to(Functor) [with Functor = TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>; R = void; T0 = const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&]’
/usr/include/boost/function/function_template.hpp:716:7: required from ‘boost::function1<R, T1>::function1(Functor, typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type) [with Functor = TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>; R = void; T0 = const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&; typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type = int]’
/usr/include/boost/function/function_template.hpp:1061:16: required from ‘boost::function<R(T0)>::function(Functor, typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type) [with Functor = TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>; R = void; T0 = const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&; typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type = int]’
/home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:89:83: required from here
/usr/include/boost/function/function_template.hpp:159:11: error: no match for call to ‘(TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)>) (const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&)’
/usr/include/boost/function/function_template.hpp:159:11: note: candidate: void (*)(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&) {aka void (*)(boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&)} <conversion>
/usr/include/boost/function/function_template.hpp:159:11: note: conversion of argument 2 would be ill-formed:
/usr/include/boost/function/function_template.hpp:159:11: error: binding reference of type ‘geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr& {aka boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&}’ to ‘const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >’ discards qualifiers
/home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:89:50: note: candidate: TCPServer::TCPServer(ros::NodeHandle*, QObject*)::<lambda(geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr&)> <near match>
[](geometry_msgs::Vector3::ConstPtr& data){std::cout<<data->x<<std::endl;});
^
/home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:89:50: note: conversion of argument 1 would be ill-formed:
In file included from /usr/include/boost/function/detail/maybe_include.hpp:18:0,
from /usr/include/boost/function/detail/function_iterate.hpp:14,
from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:52,
from /usr/include/boost/function.hpp:64,
from /opt/ros/melodic/include/ros/forwards.h:40,
from /opt/ros/melodic/include/ros/common.h:37,
from /opt/ros/melodic/include/ros/ros.h:43,
from /home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.h:7,
from /home/hari/workspace/catkin_ws/src/gui_pkg/src/tcpserver.cpp:2:
/usr/include/boost/function/function_template.hpp:159:11: error: binding reference of type ‘geometry_msgs::Vector3_<std::allocator<void> >::ConstPtr& {aka boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >&}’ to ‘const boost::shared_ptr<const geometry_msgs::Vector3_<std::allocator<void> > >’ discards qualifiers
BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
^
gui_pkg/CMakeFiles/TCPSERVER.dir/build.make:62: recipe for target 'gui_pkg/CMakeFiles/TCPSERVER.dir/src/tcpserver.cpp.o' failed
make[2]: *** [gui_pkg/CMakeFiles/TCPSERVER.dir/src/tcpserver.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
CMakeFiles/Makefile2:1735: recipe for target 'gui_pkg/CMakeFiles/TCPSERVER.dir/all' failed
make[1]: *** [gui_pkg/CMakeFiles/TCPSERVER.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j4 -l4" failed
when i used the regular function callback as shown below, it works fine
rand_dat1_sub_handle = node.subscribe<geometry_msgs::Vector3>(
"random/data1", 100,
&TCPServer::update_data1, this);
How do I use lamdas properly to represent callbacks in subscriber nodes?
I've edited the question showing the new errors after switching from geometry_msgs::Vector3Ptr& to geometry_msgs::Vector3::ConstPtr&.

Making FUSION work to display the contents of a structure

The purpose of the following code is to display the contents of a structure. It is based on this answer.
#include <iostream>
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/for_each.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/range_c.hpp>
#include <boost/bind.hpp>
struct Node {
int a = 4;
double b = 2.2;
};
BOOST_FUSION_ADAPT_STRUCT(Node, b)
struct print_visitor {
template <class Index, class C> void operator()(Index, C &c) {
std::cout << boost::fusion::extension::struct_member_name<
C, Index::value>::call() << "="
<< boost::fusion::at<Index>(c) << std::endl;
}
};
template <class C> void print_fields(C &c) {
typedef boost::mpl::range_c<
int, 0, boost::fusion::result_of::size<C>::type::value> range;
boost::mpl::for_each<range>(
boost::bind<void>(print_visitor(), _1, boost::ref(c)));
}
int main() {
Node n;
print_fields(n);
}
The compiler (gcc version 4.8.2) complains:
invalid use of incomplete type ‘struct boost::fusion::result_of::at<Node, mpl_::integral_c<int, 0> >’
typedef typename T::type type;
What is the reason and how can I resolve this?
Here is the complete output of the compiler:
-*- mode: compilation; default-directory: "~/SearchLib/AstarWithPolicies/temp/" -*-
Compilation started at Thu Dec 10 11:54:27
make -k
g++ -Wall -Wextra -Werror -std=c++11 -pedantic -I ~/boost_1_59_0 -I /usr/include/cairomm-1.0/ -I /usr/include/cairo/ -I /usr/include/sigc++-2.0/ -I /usr/lib/x86_64-linux-gnu/sigc++-2.0/include/ -I /usr/include/freetype2/ -g -c temp.cpp
In file included from /home/meir/boost_1_59_0/boost/utility/enable_if.hpp:15:0,
from /home/meir/boost_1_59_0/boost/fusion/support/tag_of.hpp:11,
from /home/meir/boost_1_59_0/boost/fusion/support/category_of.hpp:12,
from /home/meir/boost_1_59_0/boost/fusion/adapted/struct/detail/extension.hpp:14,
from /home/meir/boost_1_59_0/boost/fusion/adapted/struct/adapt_struct.hpp:27,
from temp.cpp:7:
/home/meir/boost_1_59_0/boost/core/enable_if.hpp: In instantiation of ‘struct boost::lazy_disable_if_c<false, boost::fusion::result_of::at<Node, mpl_::integral_c<int, 0> > >’:
/home/meir/boost_1_59_0/boost/core/enable_if.hpp:70:10: required from ‘struct boost::lazy_disable_if<boost::is_const<Node>, boost::fusion::result_of::at<Node, mpl_::integral_c<int, 0> > >’
/home/meir/boost_1_59_0/boost/fusion/sequence/intrinsic_fwd.hpp:102:5: required by substitution of ‘template<class N, class Sequence> constexpr typename boost::lazy_disable_if<boost::is_const<Sequence>, boost::fusion::result_of::at<Sequence, N> >::type boost::fusion::at(Sequence&) [with N = mpl_::integral_c<int, 0>; Sequence = Node]’
temp.cpp:26:48: required from ‘void print_visitor::operator()(Index, C&) [with Index = mpl_::integral_c<int, 0>; C = Node]’
/home/meir/boost_1_59_0/boost/bind/bind.hpp:315:34: required from ‘void boost::_bi::list2<A1, A2>::operator()(boost::_bi::type<void>, F&, A&, int) [with F = print_visitor; A = boost::_bi::list1<mpl_::integral_c<int, 0>&>; A1 = boost::arg<1>; A2 = boost::reference_wrapper<Node>]’
/home/meir/boost_1_59_0/boost/bind/bind.hpp:907:50: required from ‘boost::_bi::bind_t<R, F, L>::result_type boost::_bi::bind_t<R, F, L>::operator()(A1&&) [with A1 = mpl_::integral_c<int, 0>&; R = void; F = print_visitor; L = boost::_bi::list2<boost::arg<1>, boost::reference_wrapper<Node> >; boost::_bi::bind_t<R, F, L>::result_type = void]’
/home/meir/boost_1_59_0/boost/mpl/for_each.hpp:78:25: required from ‘static void boost::mpl::aux::for_each_impl<false>::execute(Iterator*, LastIterator*, TransformFunc*, F) [with Iterator = boost::mpl::r_iter<mpl_::integral_c<int, 0> >; LastIterator = boost::mpl::r_iter<mpl_::integral_c<int, 1> >; TransformFunc = boost::mpl::identity<mpl_::na>; F = boost::_bi::bind_t<void, print_visitor, boost::_bi::list2<boost::arg<1>, boost::reference_wrapper<Node> > >]’
/home/meir/boost_1_59_0/boost/mpl/for_each.hpp:105:97: required from ‘void boost::mpl::for_each(F, Sequence*, TransformOp*) [with Sequence = boost::mpl::range_c<int, 0, 1>; TransformOp = boost::mpl::identity<mpl_::na>; F = boost::_bi::bind_t<void, print_visitor, boost::_bi::list2<boost::arg<1>, boost::reference_wrapper<Node> > >]’
/home/meir/boost_1_59_0/boost/mpl/for_each.hpp:118:48: required from ‘void boost::mpl::for_each(F, Sequence*) [with Sequence = boost::mpl::range_c<int, 0, 1>; F = boost::_bi::bind_t<void, print_visitor, boost::_bi::list2<boost::arg<1>, boost::reference_wrapper<Node> > >]’
temp.cpp:34:62: required from ‘void print_fields(C&) [with C = Node]’
temp.cpp:39:19: required from here
/home/meir/boost_1_59_0/boost/core/enable_if.hpp:63:30: error: invalid use of incomplete type ‘struct boost::fusion::result_of::at<Node, mpl_::integral_c<int, 0> >’
typedef typename T::type type;
^
In file included from /home/meir/boost_1_59_0/boost/fusion/sequence/intrinsic/begin.hpp:14:0,
from /home/meir/boost_1_59_0/boost/fusion/algorithm/iteration/detail/for_each.hpp:11,
from /home/meir/boost_1_59_0/boost/fusion/algorithm/iteration/for_each.hpp:12,
from /home/meir/boost_1_59_0/boost/fusion/include/for_each.hpp:11,
from temp.cpp:9:
/home/meir/boost_1_59_0/boost/fusion/sequence/intrinsic_fwd.hpp:53:16: error: declaration of ‘struct boost::fusion::result_of::at<Node, mpl_::integral_c<int, 0> >’
struct at;
^
temp.cpp: In instantiation of ‘void print_visitor::operator()(Index, C&) [with Index = mpl_::integral_c<int, 0>; C = Node]’:
/home/meir/boost_1_59_0/boost/bind/bind.hpp:315:34: required from ‘void boost::_bi::list2<A1, A2>::operator()(boost::_bi::type<void>, F&, A&, int) [with F = print_visitor; A = boost::_bi::list1<mpl_::integral_c<int, 0>&>; A1 = boost::arg<1>; A2 = boost::reference_wrapper<Node>]’
/home/meir/boost_1_59_0/boost/bind/bind.hpp:907:50: required from ‘boost::_bi::bind_t<R, F, L>::result_type boost::_bi::bind_t<R, F, L>::operator()(A1&&) [with A1 = mpl_::integral_c<int, 0>&; R = void; F = print_visitor; L = boost::_bi::list2<boost::arg<1>, boost::reference_wrapper<Node> >; boost::_bi::bind_t<R, F, L>::result_type = void]’
/home/meir/boost_1_59_0/boost/mpl/for_each.hpp:78:25: required from ‘static void boost::mpl::aux::for_each_impl<false>::execute(Iterator*, LastIterator*, TransformFunc*, F) [with Iterator = boost::mpl::r_iter<mpl_::integral_c<int, 0> >; LastIterator = boost::mpl::r_iter<mpl_::integral_c<int, 1> >; TransformFunc = boost::mpl::identity<mpl_::na>; F = boost::_bi::bind_t<void, print_visitor, boost::_bi::list2<boost::arg<1>, boost::reference_wrapper<Node> > >]’
/home/meir/boost_1_59_0/boost/mpl/for_each.hpp:105:97: required from ‘void boost::mpl::for_each(F, Sequence*, TransformOp*) [with Sequence = boost::mpl::range_c<int, 0, 1>; TransformOp = boost::mpl::identity<mpl_::na>; F = boost::_bi::bind_t<void, print_visitor, boost::_bi::list2<boost::arg<1>, boost::reference_wrapper<Node> > >]’
/home/meir/boost_1_59_0/boost/mpl/for_each.hpp:118:48: required from ‘void boost::mpl::for_each(F, Sequence*) [with Sequence = boost::mpl::range_c<int, 0, 1>; F = boost::_bi::bind_t<void, print_visitor, boost::_bi::list2<boost::arg<1>, boost::reference_wrapper<Node> > >]’
temp.cpp:34:62: required from ‘void print_fields(C&) [with C = Node]’
temp.cpp:39:19: required from here
temp.cpp:26:48: error: no matching function for call to ‘at(Node&)’
<< boost::fusion::at<Index>(c) << std::endl;
^
temp.cpp:26:48: note: candidates are:
In file included from /home/meir/boost_1_59_0/boost/fusion/sequence/intrinsic/begin.hpp:14:0,
from /home/meir/boost_1_59_0/boost/fusion/algorithm/iteration/detail/for_each.hpp:11,
from /home/meir/boost_1_59_0/boost/fusion/algorithm/iteration/for_each.hpp:12,
from /home/meir/boost_1_59_0/boost/fusion/include/for_each.hpp:11,
from temp.cpp:9:
/home/meir/boost_1_59_0/boost/fusion/sequence/intrinsic_fwd.hpp:102:5: note: template<class N, class Sequence> constexpr typename boost::lazy_disable_if<boost::is_const<Sequence>, boost::fusion::result_of::at<Sequence, N> >::type boost::fusion::at(Sequence&)
at(Sequence& seq);
^
/home/meir/boost_1_59_0/boost/fusion/sequence/intrinsic_fwd.hpp:102:5: note: substitution of deduced template arguments resulted in errors seen above
/home/meir/boost_1_59_0/boost/fusion/sequence/intrinsic_fwd.hpp:107:5: note: template<class N, class Sequence> constexpr typename boost::fusion::result_of::at<const Sequence, N>::type boost::fusion::at(const Sequence&)
at(Sequence const& seq);
^
/home/meir/boost_1_59_0/boost/fusion/sequence/intrinsic_fwd.hpp:107:5: note: template argument deduction/substitution failed:
/home/meir/boost_1_59_0/boost/fusion/sequence/intrinsic_fwd.hpp: In substitution of ‘template<class N, class Sequence> constexpr typename boost::fusion::result_of::at<const Sequence, N>::type boost::fusion::at(const Sequence&) [with N = mpl_::integral_c<int, 0>; Sequence = Node]’:
temp.cpp:26:48: required from ‘void print_visitor::operator()(Index, C&) [with Index = mpl_::integral_c<int, 0>; C = Node]’
/home/meir/boost_1_59_0/boost/bind/bind.hpp:315:34: required from ‘void boost::_bi::list2<A1, A2>::operator()(boost::_bi::type<void>, F&, A&, int) [with F = print_visitor; A = boost::_bi::list1<mpl_::integral_c<int, 0>&>; A1 = boost::arg<1>; A2 = boost::reference_wrapper<Node>]’
/home/meir/boost_1_59_0/boost/bind/bind.hpp:907:50: required from ‘boost::_bi::bind_t<R, F, L>::result_type boost::_bi::bind_t<R, F, L>::operator()(A1&&) [with A1 = mpl_::integral_c<int, 0>&; R = void; F = print_visitor; L = boost::_bi::list2<boost::arg<1>, boost::reference_wrapper<Node> >; boost::_bi::bind_t<R, F, L>::result_type = void]’
/home/meir/boost_1_59_0/boost/mpl/for_each.hpp:78:25: required from ‘static void boost::mpl::aux::for_each_impl<false>::execute(Iterator*, LastIterator*, TransformFunc*, F) [with Iterator = boost::mpl::r_iter<mpl_::integral_c<int, 0> >; LastIterator = boost::mpl::r_iter<mpl_::integral_c<int, 1> >; TransformFunc = boost::mpl::identity<mpl_::na>; F = boost::_bi::bind_t<void, print_visitor, boost::_bi::list2<boost::arg<1>, boost::reference_wrapper<Node> > >]’
/home/meir/boost_1_59_0/boost/mpl/for_each.hpp:105:97: required from ‘void boost::mpl::for_each(F, Sequence*, TransformOp*) [with Sequence = boost::mpl::range_c<int, 0, 1>; TransformOp = boost::mpl::identity<mpl_::na>; F = boost::_bi::bind_t<void, print_visitor, boost::_bi::list2<boost::arg<1>, boost::reference_wrapper<Node> > >]’
/home/meir/boost_1_59_0/boost/mpl/for_each.hpp:118:48: required from ‘void boost::mpl::for_each(F, Sequence*) [with Sequence = boost::mpl::range_c<int, 0, 1>; F = boost::_bi::bind_t<void, print_visitor, boost::_bi::list2<boost::arg<1>, boost::reference_wrapper<Node> > >]’
temp.cpp:34:62: required from ‘void print_fields(C&) [with C = Node]’
temp.cpp:39:19: required from here
/home/meir/boost_1_59_0/boost/fusion/sequence/intrinsic_fwd.hpp:107:5: error: invalid use of incomplete type ‘struct boost::fusion::result_of::at<const Node, mpl_::integral_c<int, 0> >’
/home/meir/boost_1_59_0/boost/fusion/sequence/intrinsic_fwd.hpp:53:16: error: declaration of ‘struct boost::fusion::result_of::at<const Node, mpl_::integral_c<int, 0> >’
struct at;
^
make: *** [all] Error 1
Compilation exited abnormally with code 2 at Thu Dec 10 11:54:27
I found this post as I'm practicing the use of the MPL. I got here as I wanted to print the struct_member_name which you were successful at. The short answer is to include <boost/fusion/sequence.hpp>. fusion::at requires a sequence
BOOST_FUSION_ADAPT_STRUCT does only that, it does not create a sequence for the target. If you had have accessed the value in the same way you access the name, it would have worked.
boost::fusion::extension::access::struct_member<C, Index::value>::template apply<C>::call(x)
returns the value of interest. But of course, there is always a better way, that much code is pretty ugly. Once you have a sequence applied to your class, everything gets easier. Now, I didn't find a for_each that iterates and passes types, fusion::for_each dereferences the value and passes that to the functor. So I took some code from boost\fusion\sequence\io\out.hpp which moves across an iterator range.
This example prints the data your way, the iterator way, and directly using fusion's IO. I'm sure I'm missing a whole lot, but this is my first day of actually writing compile time code that works. Thanks for your question, I may not have gotten so far without it!
#include <iostream>
#include <boost/mpl/range_c.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/fusion/sequence.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
//https://www.boost.org/doc/libs/1_78_0/libs/fusion/doc/html/fusion/support/deduce_sequence.html
#include <boost/bind/bind.hpp>
#include <boost/fusion/iterator/distance.hpp>
struct test {
int val;
std::string name;
};
BOOST_FUSION_ADAPT_STRUCT(test,val,name)
//the origanal with changes
struct print_class
{
template <class Index, typename T>
void operator()(Index, T& x) const
{
std::cout << "from print_class: " << boost::fusion::extension::struct_member_name<T, Index::value>::call()
<< " = " << boost::fusion::at<Index>(x) << std::endl;
}
};
using namespace boost::placeholders;
template <class C> void print_fields(C& c) {
typedef boost::mpl::range_c<
int, 0, boost::fusion::result_of::size<C>::type::value> range;
boost::mpl::for_each<range>(
boost::bind<void>(print_class(), _1, boost::ref(c)));
}
//I could not find anything like this in the fusion namespace, so...
//T is a fusion iterator
namespace boost::fusion {
template <typename T>
auto get_name(){return boost::fusion::extension::struct_member_name<T::seq_type, T::index::value>::call();
}
}
//shamelessly stolen from fusion/io....
namespace {
using namespace boost;
namespace bf = fusion;
struct print_sequence_loop
{
template <typename OS, typename First, typename Last>
static void call(OS&, First&, Last&, mpl::true_)
{
}
template <typename OS, typename First, typename Last>
static void call(OS& os, First& first, Last& last, mpl::false_)
{
bf::result_of::equal_to<
typename bf::result_of::next<First>::type
, Last
>is_last;
//The code that prints
os << bf::get_name<First>() << " = ";
os << *first << std::endl;
//End the code that prints
call(os, fusion::next(first), last, is_last);
}
template <typename OS, typename First, typename Last>
static void call(OS& os, First const& first, Last const& last)
{
bf::result_of::equal_to<First, Last> eq;
call(os, first, last, eq);
}
};
template <typename OS, typename Sequence>
inline void print_sequence(OS& os, Sequence& seq)
{
print_sequence_loop::call(os, fusion::begin(seq), fusion::end(seq));
}
}
using boost::fusion::operators::operator<<;
int main() {
test the_test{ 12,"this is me" };
print_sequence(std::cout, the_test);
std::cout << '\n';
print_fields(the_test);
std::cout << "\n\n this is using fusions OS\n";
std::cout << the_test << std::endl;
}
GCC demo And it works with MSVC.

Boost::bind a sigaction function reference to a instance

I would like to use a Linux kernel signal to asynchronously communicate the occurrence of an event from a module to a user-space application. I have this working in C in the following way:
void rcv_signal(int n, siginfo_t *info, void *unused)
{
// Do something interesting with the signal
}
// Register for updates from the kernel
int main(int argc, char *argv[])
{
struct sigaction sig;
sig.sa_sigaction = rcv_signal; // Function pointer
sig.sa_flags = SA_SIGINFO;
sigaction(SOME_CUSTOM_SIGNAL, &sig, NULL);
// Code to wait() then return
}
Now, I would like to move to C++ implementation. More specifically, I would like to use boost::function / boost::bind to bind the sa_sigaction to a method InputCapture::receive. However, I am struggling to get the correct function signature.
Here is the definition of the InputCapture Class:
class InputCapture
{
public: InputCapture(uint8_t intimer) : timer(_timer) {}
public: ~InputCapture() {}
private: void receive(int n, siginfo_t *info, void *unused) {}
private: uint8_t timer;
};
And here is the modified sa_sigaction:
// Register for updates from the kernel
struct sigaction sig;
sig.sa_sigaction = boost::function<void (int n, siginfo_t *info, void *unused)> (
boost::bind(&InputCapture::receive, this, _1));
sig.sa_flags = SA_SIGINFO;
sigaction(SOME_CUSTOM_SIGNAL, &sig, NULL);
However, I get the following compilation error:
In file included from /home/asymingt/export/rootfs/usr/include/boost/bind.hpp:22:0,
from /home/asymingt/Workspace/Source/roseline/timesync/src/stamp/LogicalStamp.hpp:12,
from /home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.hpp:4,
from /home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp:1:
/home/asymingt/export/rootfs/usr/include/boost/bind/bind.hpp: In instantiation of ‘struct boost::_bi::result_traits’:
/home/asymingt/export/rootfs/usr/include/boost/bind/bind_template.hpp:15:48: required from ‘class boost::_bi::bind_t)(int, siginfo, void*), boost::_bi::list2, boost::arg<1> > >’
/home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp:41:57: required from here
/home/asymingt/export/rootfs/usr/include/boost/bind/bind.hpp:69:37: error: ‘void (timesync::InputCapture::)(int, siginfo, void*)’ is not a class, struct, or union type
typedef typename F::result_type type;
^
/home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp: In constructor ‘timesync::InputCapture::InputCapture(uint8_t)’:
/home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp:40:19: error: cannot convert ‘boost::function’ to ‘void ()(int, siginfo_t, void*) {aka void ()(int, siginfo, void*)}’ in assignment
sig.sa_sigaction = boost::function (
^
In file included from /home/asymingt/export/rootfs/usr/include/boost/function/detail/maybe_include.hpp:28:0,
from /home/asymingt/export/rootfs/usr/include/boost/function/detail/function_iterate.hpp:14,
from /home/asymingt/export/rootfs/usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:62,
from /home/asymingt/export/rootfs/usr/include/boost/function.hpp:64,
from /home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp:3:
/home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp: In instantiation of ‘static void boost::detail::function::void_function_obj_invoker3::invoke(boost::detail::function::function_buffer&, T0, T1, T2) [with FunctionObj = boost::_bi::bind_t)(int, siginfo, void*), boost::_bi::list2, boost::arg<1> > >; R = void; T0 = int; T1 = siginfo*; T2 = void*]’:
/home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp:907:38: required from ‘void boost::function3::assign_to(Functor) [with Functor = boost::_bi::bind_t)(int, siginfo, void*), boost::_bi::list2, boost::arg<1> > >; R = void; T0 = int; T1 = siginfo*; T2 = void*]’
/home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp:722:7: required from ‘boost::function3::function3(Functor, typename boost::enable_if_c::value>::value, int>::type) [with Functor = boost::_bi::bind_t)(int, siginfo, void*), boost::_bi::list2, boost::arg<1> > >; R = void; T0 = int; T1 = siginfo*; T2 = void*; typename boost::enable_if_c::value>::value, int>::type = int]’
/home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp:1042:16: required from ‘boost::function::function(Functor, typename boost::enable_if_c::value>::value, int>::type) [with Functor = boost::_bi::bind_t)(int, siginfo, void*), boost::_bi::list2, boost::arg<1> > >; R = void; T0 = int; T1 = siginfo*; T2 = void*; typename boost::enable_if_c::value>::value, int>::type = int]’
/home/asymingt/Workspace/Source/roseline/timesync/src/stamp/InputCapture.cpp:41:58: required from here
/home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp:153:57: error: no match for call to ‘(boost::_bi::bind_t)(int, siginfo, void*), boost::_bi::list2, boost::arg<1> > >) (int&, siginfo*&, void*&)’
BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
^
/home/asymingt/export/rootfs/usr/include/boost/function/function_template.hpp:75:36: note: in definition of macro ‘BOOST_FUNCTION_RETURN’
# define BOOST_FUNCTION_RETURN(X) X
Is what I am trying to achieve possible, and if so, where have I gone wrong?
You cannot do this.
Note that sigaction::sa_sigaction is a pointer to function. Neither boost::function, nor the return value of boost::bind are convertible to a function pointer!

Clarification on the use of `boost::bind` and `this`

I was making some modifications to a boost::asio project today and I ran into a confusing compilation error when attempting to pass a bound function into an async call.
I have spent hours fiddling with this code, so I suspect I am missing something stupid. I would appreciate anyone who can point out where I am going wrong.
error: no match for call to ‘(boost::_mfi::mf3<void, ClientServerManager,
const MCServer&, boost::shared_ptr<Connection>,
const boost::system::error_code&>) (ClientServerManager*&,
MCServer&, boost::shared_ptr<Connection>&,
const MCServer&)’
Notice that const MCServer& appears twice? That isn't how my bind statement is written:
void ClientServerManager::onConnect(const MCServer& server_info,
boost::shared_ptr<Connection> con,
const boost::system::error_code& err,
tcp::resolver::iterator i) {
// Instruct utility to do some work, and call our function when complete.
con->statusPing(
boost::bind( // <-- OFFENDING CODE
&ClientServerManager::onPingCompletion,
this,
server_info,
con, // shared_ptr to connection (maintains scope)
boost::asio::placeholders::error // in case of a downstream failure
)
);
}
In the Connection header statusPing(...) is defined as follows:
void statusPing(boost::function<
void(
MCServer&, boost::shared_ptr<Connection>,
const boost::system::error_code&
)>);
The handler eventually to be called:
void ClientServerManager::onPingCompletion(
const MCServer& server_info,
boost::shared_ptr<Connection>,
const boost::system::error_code& err){
// Use the results to drive some function...
}
Background:
I have a class which iterates through a list of servers and opens
short-lived connections with them to make sure they are operating
properly.
The class uses a utility, Connection which inherits
boost::enable_shared_from_this. Therefore, I call a function, Connection::create(..) to grab a boost::shared_ptr to start work with. When any async calls are made, this pointer has to be passed to keep the connection in scope.
In this instance after the connection is successfully established, I want to pass execution to Connection such that it can execute some tasks, and I want it to call a handle once those tasks are complete. I cannot get boost::bind to compile properly in this case.
Now the issue I am having is that the boost::bind might be linked to the use of the boost::asio::placeholders::error template.
The full output follows:
g++ -std=c++0x -DBOOST_LOG_DYN_LINK -I/home/donald/Desktop/workspace/MCProxy/Debug/ -O3 -march=corei7-avx -g1 -w -c -fmessage-length=0 -MMD -MP -MF"src/ClientServerManager.d" -MT"src/ClientServerManager.d" -o "src/ClientServerManager.o" "../src/ClientServerManager.cpp"
In file included from ....
/boost/bind/bind.hpp: In instantiation of ‘void boost::_bi::list4<A1, A2, A3, A4>::operator()(boost::_bi::type<void>, F&, A&, int) [with F = boost::_mfi::mf3<void, ClientServerManager, const MCServer&, boost::shared_ptr<Connection>, const boost::system::error_code&>; A = boost::_bi::list3<const MCServer&, boost::shared_ptr<Connection>&, const boost::system::error_code&>; A1 = boost::_bi::value<ClientServerManager*>; A2 = boost::_bi::value<MCServer>; A3 = boost::_bi::value<boost::shared_ptr<Connection> >; A4 = boost::arg<1> (*)()]’:
/boost/bind/bind_template.hpp:116:59: required from ‘boost::_bi::bind_t<R, F, L>::result_type boost::_bi::bind_t<R, F, L>::operator()(A1&, A2&, A3&) [with A1 = const MCServer; A2 = boost::shared_ptr<Connection>; A3 = const boost::system::error_code; R = void; F = boost::_mfi::mf3<void, ClientServerManager, const MCServer&, boost::shared_ptr<Connection>, const boost::system::error_code&>; L = boost::_bi::list4<boost::_bi::value<ClientServerManager*>, boost::_bi::value<MCServer>, boost::_bi::value<boost::shared_ptr<Connection> >, boost::arg<1> (*)()>; boost::_bi::bind_t<R, F, L>::result_type = void]’
/boost/function/function_template.hpp:153:11: required from ‘static void boost::detail::function::void_function_obj_invoker3<FunctionObj, R, T0, T1, T2>::invoke(boost::detail::function::function_buffer&, T0, T1, T2) [with FunctionObj = boost::_bi::bind_t<void, boost::_mfi::mf3<void, ClientServerManager, const MCServer&, boost::shared_ptr<Connection>, const boost::system::error_code&>, boost::_bi::list4<boost::_bi::value<ClientServerManager*>, boost::_bi::value<MCServer>, boost::_bi::value<boost::shared_ptr<Connection> >, boost::arg<1> (*)()> >; R = void; T0 = const MCServer&; T1 = boost::shared_ptr<Connection>; T2 = const boost::system::error_code&]’
/boost/function/function_template.hpp:934:60: required from ‘void boost::function3<R, T1, T2, T3>::assign_to(Functor) [with Functor = boost::_bi::bind_t<void, boost::_mfi::mf3<void, ClientServerManager, const MCServer&, boost::shared_ptr<Connection>, const boost::system::error_code&>, boost::_bi::list4<boost::_bi::value<ClientServerManager*>, boost::_bi::value<MCServer>, boost::_bi::value<boost::shared_ptr<Connection> >, boost::arg<1> (*)()> >; R = void; T0 = const MCServer&; T1 = boost::shared_ptr<Connection>; T2 = const boost::system::error_code&]’
/boost/function/function_template.hpp:722:7: required from ‘boost::function3<R, T1, T2, T3>::function3(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::_bi::bind_t<void, boost::_mfi::mf3<void, ClientServerManager, const MCServer&, boost::shared_ptr<Connection>, const boost::system::error_code&>, boost::_bi::list4<boost::_bi::value<ClientServerManager*>, boost::_bi::value<MCServer>, boost::_bi::value<boost::shared_ptr<Connection> >, boost::arg<1> (*)()> >; R = void; T0 = const MCServer&; T1 = boost::shared_ptr<Connection>; T2 = const boost::system::error_code&; typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’
/boost/function/function_template.hpp:1071:16: required from ‘boost::function<R(T0, T1, T2)>::function(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::_bi::bind_t<void, boost::_mfi::mf3<void, ClientServerManager, const MCServer&, boost::shared_ptr<Connection>, const boost::system::error_code&>, boost::_bi::list4<boost::_bi::value<ClientServerManager*>, boost::_bi::value<MCServer>, boost::_bi::value<boost::shared_ptr<Connection> >, boost::arg<1> (*)()> >; R = void; T0 = const MCServer&; T1 = boost::shared_ptr<Connection>; T2 = const boost::system::error_code&; typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’
../src/ClientServerManager.cpp:90:3: required from here
/boost/bind/bind.hpp:457:9: error: no match for call to ‘(boost::_mfi::mf3<void, ClientServerManager, const MCServer&, boost::shared_ptr<Connection>, const boost::system::error_code&>) (ClientServerManager*&, MCServer&, boost::shared_ptr<Connection>&, const MCServer&)’
In file included ....
/boost/bind/mem_fn_template.hpp:366:85: note: candidates are:
/boost/bind/mem_fn_template.hpp:391:7: note: R boost::_mfi::mf3<R, T, A1, A2, A3>::operator()(T*, A1, A2, A3) const [with R = void; T = ClientServerManager; A1 = const MCServer&; A2 = boost::shared_ptr<Connection>; A3 = const boost::system::error_code&]
/boost/bind/mem_fn_template.hpp:391:7: note: no known conversion for argument 4 from ‘const MCServer’ to ‘const boost::system::error_code&’
/boost/bind/mem_fn_template.hpp:396:25: note: template<class U> R boost::_mfi::mf3::operator()(U&, A1, A2, A3) const [with U = U; R = void; T = ClientServerManager; A1 = const MCServer&; A2 = boost::shared_ptr<Connection>; A3 = const boost::system::error_code&]
/boost/bind/mem_fn_template.hpp:396:25: note: template argument deduction/substitution failed:
In file included ....
/boost/bind/bind.hpp:457:9: note: cannot convert ‘(& a)->boost::_bi::list3<A1, A2, A3>::operator[]<const MCServer&, boost::shared_ptr<Connection>&, const boost::system::error_code&>(boost::_bi::storage4<A1, A2, A3, boost::arg<I> (*)()>::a4_<boost::_bi::value<ClientServerManager*>, boost::_bi::value<MCServer>, boost::_bi::value<boost::shared_ptr<Connection> >, 1>)’ (type ‘const MCServer’) to type ‘const boost::system::error_code&’
In file included ....
/boost/bind/mem_fn_template.hpp:404:25: note: template<class U> R boost::_mfi::mf3::operator()(const U&, A1, A2, A3) const [with U = U; R = void; T = ClientServerManager; A1 = const MCServer&; A2 = boost::shared_ptr<Connection>; A3 = const boost::system::error_code&]
/boost/bind/mem_fn_template.hpp:404:25: note: template argument deduction/substitution failed:
In file included ....
/boost/bind/bind.hpp:457:9: note: cannot convert ‘(& a)->boost::_bi::list3<A1, A2, A3>::operator[]<const MCServer&, boost::shared_ptr<Connection>&, const boost::system::error_code&>(boost::_bi::storage4<A1, A2, A3, boost::arg<I> (*)()>::a4_<boost::_bi::value<ClientServerManager*>, boost::_bi::value<MCServer>, boost::_bi::value<boost::shared_ptr<Connection> >, 1>)’ (type ‘const MCServer’) to type ‘const boost::system::error_code&’
In file included from ....
/boost/bind/mem_fn_template.hpp:412:7: note: R boost::_mfi::mf3<R, T, A1, A2, A3>::operator()(T&, A1, A2, A3) const [with R = void; T = ClientServerManager; A1 = const MCServer&; A2 = boost::shared_ptr<Connection>; A3 = const boost::system::error_code&]
/boost/bind/mem_fn_template.hpp:412:7: note: no known conversion for argument 1 from ‘ClientServerManager*’ to ‘ClientServerManager&’
Edit: (boost::function<void(...)> -> boost::function<void()>)
Per suggestion, I changed the Connection function to read void statusPing(boost::function<void()>); as the parameters are bound in. This change yields a different error:
g++ -std=c++0x -DBOOST_LOG_DYN_LINK -I/home/donald/Desktop/workspace/MCProxy/Debug/ -O3 -march=corei7-avx -g1 -w -c -fmessage-length=0 -MMD -MP -MF"src/ClientServerManager.d" -MT"src/ClientServerManager.d" -o "src/ClientServerManager.o" "../src/ClientServerManager.cpp"
In file included from ....
/boost/bind/bind.hpp: In instantiation of ‘void boost::_bi::list4<A1, A2, A3, A4>::operator()(boost::_bi::type<void>, F&, A&, int) [with F = boost::_mfi::mf3<void, ClientServerManager, const MCServer&, boost::shared_ptr<Connection>&, const boost::system::error_code&>; A = boost::_bi::list0; A1 = boost::_bi::value<ClientServerManager*>; A2 = boost::_bi::value<MCServer>; A3 = boost::_bi::value<boost::shared_ptr<Connection> >; A4 = boost::arg<1> (*)()]’:
/boost/bind/bind_template.hpp:20:59: required from ‘boost::_bi::bind_t<R, F, L>::result_type boost::_bi::bind_t<R, F, L>::operator()() [with R = void; F = boost::_mfi::mf3<void, ClientServerManager, const MCServer&, boost::shared_ptr<Connection>&, const boost::system::error_code&>; L = boost::_bi::list4<boost::_bi::value<ClientServerManager*>, boost::_bi::value<MCServer>, boost::_bi::value<boost::shared_ptr<Connection> >, boost::arg<1> (*)()>; boost::_bi::bind_t<R, F, L>::result_type = void]’
/boost/function/function_template.hpp:153:11: required from ‘static void boost::detail::function::void_function_obj_invoker0<FunctionObj, R>::invoke(boost::detail::function::function_buffer&) [with FunctionObj = boost::_bi::bind_t<void, boost::_mfi::mf3<void, ClientServerManager, const MCServer&, boost::shared_ptr<Connection>&, const boost::system::error_code&>, boost::_bi::list4<boost::_bi::value<ClientServerManager*>, boost::_bi::value<MCServer>, boost::_bi::value<boost::shared_ptr<Connection> >, boost::arg<1> (*)()> >; R = void]’
/boost/function/function_template.hpp:934:60: required from ‘void boost::function0<R>::assign_to(Functor) [with Functor = boost::_bi::bind_t<void, boost::_mfi::mf3<void, ClientServerManager, const MCServer&, boost::shared_ptr<Connection>&, const boost::system::error_code&>, boost::_bi::list4<boost::_bi::value<ClientServerManager*>, boost::_bi::value<MCServer>, boost::_bi::value<boost::shared_ptr<Connection> >, boost::arg<1> (*)()> >; R = void]’
/boost/function/function_template.hpp:722:7: required from ‘boost::function0<R>::function0(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::_bi::bind_t<void, boost::_mfi::mf3<void, ClientServerManager, const MCServer&, boost::shared_ptr<Connection>&, const boost::system::error_code&>, boost::_bi::list4<boost::_bi::value<ClientServerManager*>, boost::_bi::value<MCServer>, boost::_bi::value<boost::shared_ptr<Connection> >, boost::arg<1> (*)()> >; R = void; typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’
/boost/function/function_template.hpp:1071:16: required from ‘boost::function<R()>::function(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::_bi::bind_t<void, boost::_mfi::mf3<void, ClientServerManager, const MCServer&, boost::shared_ptr<Connection>&, const boost::system::error_code&>, boost::_bi::list4<boost::_bi::value<ClientServerManager*>, boost::_bi::value<MCServer>, boost::_bi::value<boost::shared_ptr<Connection> >, boost::arg<1> (*)()> >; R = void; typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’
../src/ClientServerManager.cpp:90:2: required from here
/boost/bind/bind.hpp:457:9: error: no match for ‘operator[]’ in ‘a[boost::_bi::storage4<A1, A2, A3, boost::arg<I> (*)()>::a4_<boost::_bi::value<ClientServerManager*>, boost::_bi::value<MCServer>, boost::_bi::value<boost::shared_ptr<Connection> >, 1>]’
/boost/bind/bind.hpp:457:9: note: candidates are:
In file included ....
/boost/bind/bind.hpp:170:27: note: template<class T> T& boost::_bi::list0::operator[](boost::_bi::value<T>&) const
/boost/bind/bind.hpp:170:27: note: template argument deduction/substitution failed:
In file included ....
/boost/bind/bind.hpp:457:9: note: mismatched types ‘boost::_bi::value<T>’ and ‘boost::arg<1>()’
In file included ....
/boost/bind/bind.hpp:172:33: note: template<class T> const T& boost::_bi::list0::operator[](const boost::_bi::value<T>&) const
/boost/bind/bind.hpp:172:33: note: template argument deduction/substitution failed:
In file included ....
/boost/bind/bind.hpp:457:9: note: mismatched types ‘const boost::_bi::value<T>’ and ‘boost::arg<1>()’
In file included ....
/boost/bind/bind.hpp:174:27: note: template<class T> T& boost::_bi::list0::operator[](const boost::reference_wrapper<T>&) const
/boost/bind/bind.hpp:174:27: note: template argument deduction/substitution failed:
In file included from ....
/boost/bind/bind.hpp:457:9: note: mismatched types ‘const boost::reference_wrapper<T>’ and ‘boost::arg<1>()’
In file included from ....
/boost/bind/bind.hpp:176:76: note: template<class R, class F, class L> typename boost::_bi::result_traits<R, F>::type boost::_bi::list0::operator[](boost::_bi::bind_t<R, F, L>&) const
/boost/bind/bind.hpp:176:76: note: template argument deduction/substitution failed:
In file included from ....
/boost/bind/bind.hpp:457:9: note: mismatched types ‘boost::_bi::bind_t<R, F, L>’ and ‘boost::arg<1>()’
/boost/bind/bind.hpp:178:76: note: template<class R, class F, class L> typename boost::_bi::result_traits<R, F>::type boost::_bi::list0::operator[](const boost::_bi::bind_t<R, F, L>&) const
/boost/bind/bind.hpp:178:76: note: template argument deduction/substitution failed:
/boost/bind/bind.hpp:457:9: note: mismatched types ‘const boost::_bi::bind_t<R, F, L>’ and ‘boost::arg<1>()’
make: *** [src/ClientServerManager.o] Error 1
A simplified example:
#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
#include <boost/asio.hpp>
#include <boost/system/error_code.hpp>
#include <boost/function.hpp>
class ExampleWorker {
public:
void statusPing(boost::function<void()> f){
// Do work.
f(); // Call handle
}
};
class SomeObject {};
void someHandle(boost::shared_ptr<SomeObject> obj,
const boost::system::error_code& err){
// ...
}
int main() {
ExampleWorker* e = new ExampleWorker();
boost::shared_ptr<SomeObject> ptr(new SomeObject());
e->statusPing(
boost::bind(
&someHandle,
ptr,
boost::asio::placeholders::error
)
);
}
boost::asio::placeholders::error is just like using boost::placeholders::_1 with boost::bind, and when you pass a bind expression containing that to an asio completion handler function, the function will invoke your handler with the boost::system::error_code result from the operation it performed, thus allowing your handler access to the error code.
In your second example, the boost::function signature for the following bind expression
boost::bind(
&someHandle,
ptr,
boost::asio::placeholders::error
)
is
boost::function<void(boost::system::error_code const&)>
To get your code to compile, change the statusPing() member function to
void statusPing(boost::function<void(boost::system::error_code const&)> f){
// Do work.
boost::system::error_code err;
f(err); // Call handle
}

boost::variant, shared-ptr error in assignment

I'm have the following elements:
#define TEMPLATE_PARAM boost::variant<int, const std::string&, const std::vector<std::string>&, const std::vector<int>&, const ITemplateLoop*, const std::vector<ITemplateLoop*>&>
class PostParam
{
...
const std::string &getParam() const;
};
class ParamContainer
{
std::map<std::string, TEMPLATE_PARAM> map_;
template <typename T>
void insert(std::string key, const T & value)
{
map_[key] = value;
}
public:
template<typename ... Args>
void add(std::map<std::string, std::shared_ptr<PostParam>>& param, Args ... args)
{
for (const auto & key : param)
insert(key.first, key.second->getParam());
if (sizeof ...(Args) > 0)
add(args...);
}
I am getting a lot of compilation error and I don't know what to paste here
/usr/local/include/boost/detail/reference_content.hpp: In member function 'void boost::detail::variant::move_storage::internal_visit(T&, int) const [with T = boost::de tail::reference_content<const std::basic_string<char>&>]':
/usr/local/include/boost/variant/detail/visitation_impl.hpp:130:9: instantiated from 'typename Visitor::result_type boost::detail::variant::visitation_impl_invoke_impl(int, Visitor&, VoidPtrCV, T*, mpl_::true_) [with Visitor = boost::detail::variant::move_storage, VoidPtrCV = void*, T = boost::detail::reference_content<const std::basic_string<char>&>, typename Visitor::result_type = void, mpl_::true_ = mpl_::bool_<true>]'
/usr/local/include/boost/variant/detail/visitation_impl.hpp:173:9: instantiated from 'typename Visitor::result_type boost::detail::variant::visitation_impl_invoke(int, Visitor&, VoidPtrCV, T*, NoBackupFlag, int) [with Visitor=boost::detail::variant::move_storage, VoidPtrCV = void*, T = boost::detail::reference_content<const std::basic_string<char>&>, NoBackupFlag = boost::variant<int, const std::basic_string<char>&, const std::vector<std::basic_string<char> >&, const std::vector<int>&, const TemplateEngine::ITemplateLoop*, const std::vector<TemplateEngine::ITemplateLoop*>&, const PostParam&>::has_fallback_type_, typename Visitor::result_type = void]'
/usr/local/include/boost/variant/detail/visitation_impl.hpp:260:1: instantiated from 'typename Visitor::result_type boost::detail::variant::visitation_impl(int, int, Visitor&, VoidPtrCV, mpl_::false_, NoBackupFlag, Which*, step0*) [with Which = mpl_::int_<0>, step0 = boost::detail::variant::visitation_impl_step<boost::mpl::l_iter< boost::mpl::l_item<mpl_::long_<7l>, int, boost::mpl::l_item<mpl_::long_<6l>, boost::detail::reference_content<const std::basic_string<char>&>, boost::mpl::l_item<mpl_: :long_<5l>, boost::detail::reference_content<const std::vector<std::basic_string<char> >&>, boost::mpl::l_item<mpl_::long_<4l>, boost::detail::reference_content<const std::vector<int>&>, boost::mpl::l_item<mpl_::long_<3l>, const TemplateEngine::ITemplateLoop*, boost::mpl::l_item<mpl_::long_<2l>, boost::detail::reference_content<const std::vector<TemplateEngine::ITemplateLoop*>&>, boost::mpl::l_item<mpl_::long_<1l>, boost::detail::reference_content<const PostParam&>, boost::mpl::l_end> > > > > > > >, boost::mpl::l_iter<boost::mpl::l_end> >, Visitor = boost::detail::variant::move_storage, VoidPtrCV = void*, NoBackupFlag = boost::variant<int, const std::basic_string<char>&, const std::vector<std::basic_string<char> >&, const std::vector<int>&, const TemplateEngine::ITemplateLoop*, const std::vector<TemplateEngine::ITemplateLoop*>&, const PostParam&>::has_fallback_type_, typename Visitor::result_type = void, mpl_::false_ = mpl_::bool_<false>]'
I think it's the parameter that I get using key.second->getParam() but I'm unable to find a solution
Edit
I have changed the #define to the typedef
So the error message
/home/django/cloaked-ninja/includes/TemplateEngine.hpp:67:7: instantiated from 'void TemplateEngine::ParamContainer::insert(std::string, const T&) [with T = std::basic_string<char>, std::string = std::basic_string<char>]'
/home/django/cloaked-ninja/includes/TemplateEngine.hpp:94:2: instantiated from 'void TemplateEngine::ParamContainer::add(std::map<std::basic_string<char>, std::shared_ptr<PostParam> >&, Args ...) [with Args = {}]'
/home/django/cloaked-ninja/src/Controller/ControllerPost.cpp:22:14: instantiated from here
/usr/local/include/boost/detail/reference_content.hpp:62:24: error: 'boost::detail::reference_content<RefT>& boost::detail::reference_content<RefT>::operator=(const boost::detail::reference_content<RefT>&) [with RefT = const std::basic_string<char>&, boost::detail::reference_content<RefT> = boost::detail::reference_content<const std::basic_string<char>&>]' is private
/usr/local/include/boost/variant/variant.hpp:583:9: error: within this context
/usr/local/include/boost/detail/reference_content.hpp: In member function 'void boost::detail::variant::move_storage::internal_visit(T&, int) const [with T = boost::de tail::reference_content<const std::vector<std::basic_string<char> >&>]':
/usr/local/include/boost/variant/detail/visitation_impl.hpp:130:9: instantiated from 'typename Visitor::result_type boost::detail::variant::visitation_impl_invoke_impl(int, Visitor&, VoidPtrCV, T*, mpl_::true_) [with Visitor = boost::detail::variant::move_storage, VoidPtrCV = void*, T = boost::detail::reference_content<const std::vector<std::basic_string<char> >&>, typename Visitor::result_type = void, mpl_::true_ = mpl_::bool_<true>]'
/usr/local/include/boost/detail/reference_content.hpp: In member function 'void boost::detail::variant::move_storage::internal_visit(T&, int) const [with T = boost::detail::reference_content<const std::vector<std::basic_string<char> >&>]':
/usr/local/include/boost/variant/detail/visitation_impl.hpp:130:9: instantiated from 'typename Visitor::result_type boost::detail::variant::visitation_impl_invoke_impl(int, Visitor&, VoidPtrCV, T*, mpl_::true_) [with Visitor = boost::detail::variant::move_storage, VoidPtrCV = void*, T = boost::detail::reference_content<const
std::vector<std::basic_string<char> >&>, typename Visitor::result_type = void, mpl_::true_ = mpl_::bool_<true>]'
/usr/local/include/boost/variant/detail/visitation_impl.hpp:173:9: instantiated from 'typename Visitor::result_type boost::detail::variant::visitation_impl_invoke(int, Visitor&, VoidPtrCV, T*, NoBackupFlag, int) [with Visitor = boost::detail::variant::move_storage, VoidPtrCV = void*, T = boost::detail::reference_content<const std::vector<std::basic_string<char> >&>, NoBackupFlag = boost::variant<int, const std::basic_string<char>&, const std::vector<std::basic_string<char> >&, const std::vector<int>&, const TemplateEngine::ITemplateLoop*, const std::vector<TemplateEngine::ITemplateLoop*>&>::has_fallback_type_, typename Visitor::result_type = void]'
/usr/local/include/boost/variant/detail/visitation_impl.hpp:260:1: instantiated from 'typename Visitor::result_type boost::detail::variant::visitation_impl(int, int, Visitor&, VoidPtrCV, mpl_::false_, NoBackupFlag, Which*, step0*) [with Which = mpl_::int_<0>, step0 = boost::detail::variant::visitation_impl_step<boost::mpl::l_iter<boost::mpl::l_item<mpl_::long_<6l>, int, boost::mpl::l_item<mpl_::long_<5l>, boost::detail::reference_content<const std::basic_string<char>&>, boost::mpl::l_item<mpl_::long_<4l>, boost::detail::reference_content<const std::vector<std::basic_string<char> >&>, boost::mpl::l_item<mpl_::long_<3l>, boost::detail::reference_content<const std::vector<int>&>, boost::mpl::l_item<mpl_::long_<2l>, const TemplateEngine::ITemplateLoop*, boost::mpl::l_item<mpl_::long_<1l>, boost::detail::reference_content<const std::vector<TemplateEngine::ITemplateLoop*>&>, boost::mpl::l_end> > > > > > >, boost::mpl::l_iter<boost::mpl::l_end> >, Visitor = boost::detail::variant::move_storage, VoidPtrCV = void*, NoBackupFlag = boost::variant<int, const std::basic_string<char>&, const std::vector<std::basic_string<char> >&, const std::vector<int>&, const TemplateEngine::ITemplateLoop*, const std::vector<TemplateEngine::ITemplateLoop*>&>::has_fallback_type_, typename Visitor::result_type = void, mpl_::false_ = mpl_::bool_<false>]'
Edit2
I have just changed the #define to the following typedef and it's now working:
typedef boost::variant<int, const std::string*, const std::vector<std::string>*, const std::vector<int>*, const ITemplateLoop*, const std::vector<ITemplateLoop*>*> TEMPLATE_PARAM;
If I'm not completely mistaken, the problem lies within your variant declaration. boost::variant can not take values as const &, because a copy of the data is required.
Here is a minimal working example:
#include <boost/variant.hpp>
#include <string>
#include <map>
struct foo
{
typedef boost::variant<int, std::string> variant;
std::map<std::string, variant> map;
template <typename T>
void insert(std::string const & key, T const & value)
{
map[key] = value;
}
};
int main()
{
foo f;
f.insert("test", "foo");
return 0;
}