It appears that the create_processor implementation instantiates code
that attempts to copy the argument.
It does, and this is why you must pass boost::ref wrapper instead of the reference itself.
processor1 =
scheduler.create_processor
(boost::ref(value));
Here you instruct the compiler to convert the parameter into Object &, and therefore
boost::ref has no effect, as the conversion takes place "before" the create_processor
call. Just omit the "Object &" template parameter and let the compiler deduce it and
the code should compile.
HTH
Juraj Ivančić
Good point. I had tried this, as well as specifying the template parameter type
as boost::reference_wrapper<Object>.
Here is the result with create_processor<Test>(boost::ref(value)):
g++ -Wall -o test test.cc
/usr/include/boost/bind.hpp: In member function 'void boost::_bi::list4::operator()(boost::_bi::type<void>, F&, A&, int) [with F = boost::_mfi::mf3, std::allocator<void> >, boost::function0<void>, std::allocator<void> >, const boost::shared_ptr, std::allocator<void> > > > >&, const boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, boost::reference_wrapper<Object> >, A = boost::_bi::list0, A1 = boost::_bi::value, std::allocator<void> >, boost::function0<void>, std::allocator<void> >*>, A2 = boost::_bi::value, std::allocator<void> > > > > >, A3 = boost::_bi::value, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context>, A4 = boost::reference_wrapper<Object>]':
/usr/include/boost/bind/bind_template.hpp:20: instantiated from 'typename boost::_bi::result_traits::type boost::_bi::bind_t::operator()() [with R = void, F = boost::_mfi::mf3, std::allocator<void> >, boost::function0<void>, std::allocator<void> >, const boost::shared_ptr, std::allocator<void> > > > >&, const boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, boost::reference_wrapper<Object> >, L = boost::_bi::list4, std::allocator<void> >, boost::function0<void>, std::allocator<void> >*>, boost::_bi::value, std::allocator<void> > > > > >, boost::_bi::value, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context>, boost::reference_wrapper<Object> >]'
/usr/include/boost/function/function_template.hpp:152: instantiated from 'static void boost::detail::function::void_function_obj_invoker0::invoke(boost::detail::function::function_buffer&) [with FunctionObj = boost::_bi::bind_t, std::allocator<void> >, boost::function0<void>, std::allocator<void> >, const boost::shared_ptr, std::allocator<void> > > > >&, const boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, boost::reference_wrapper<Object> >, boost::_bi::list4, std::allocator<void> >, boost::function0<void>, std::allocator<void> >*>, boost::_bi::value, std::allocator<void> > > > > >, boost::_bi::value, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context>, boost::reference_wrapper<Object> > >, R = void]'
/usr/include/boost/function/function_template.hpp:931: instantiated from 'void boost::function0<R>::assign_to_a(Functor, Allocator) [with Functor = boost::_bi::bind_t, std::allocator<void> >, boost::function0<void>, std::allocator<void> >, const boost::shared_ptr, std::allocator<void> > > > >&, const boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, boost::reference_wrapper<Object> >, boost::_bi::list4, std::allocator<void> >, boost::function0<void>, std::allocator<void> >*>, boost::_bi::value, std::allocator<void> > > > > >, boost::_bi::value, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context>, boost::reference_wrapper<Object> > >, Allocator = std::allocator<void>, R = void]'
/usr/include/boost/function/function_template.hpp:733: instantiated from 'boost::function0<R>::function0(Functor, Allocator, typename boost::enable_if_c::type) [with Functor = boost::_bi::bind_t, std::allocator<void> >, boost::function0<void>, std::allocator<void> >, const boost::shared_ptr, std::allocator<void> > > > >&, const boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, boost::reference_wrapper<Object> >, boost::_bi::list4, std::allocator<void> >, boost::function0<void>, std::allocator<void> >*>, boost::_bi::value, std::allocator<void> > > > > >, boost::_bi::value, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context>, boost::reference_wrapper<Object> > >, Allocator = std::allocator<void>, R = void]'
/usr/include/boost/statechart/processor_container.hpp:112: instantiated from 'WorkItem boost::statechart::processor_container::create_processor(boost::weak_ptr >&, Scheduler&, Arg1) [with Processor = Test, Arg1 = boost::reference_wrapper<Object>, Scheduler = boost::statechart::fifo_scheduler, std::allocator<void> >, WorkItem = boost::function0<void>, Allocator = std::allocator<void>]'
/usr/include/boost/statechart/fifo_scheduler.hpp:63: instantiated from 'typename boost::statechart::processor_container, typename FifoWorker::work_item, Allocator>::processor_handle boost::statechart::fifo_scheduler::create_processor(Arg1) [with Processor = Test, Arg1 = boost::reference_wrapper<Object>, FifoWorker = boost::statechart::fifo_worker, Allocator = std::allocator<void>]'
test.cc:36: instantiated from here
/usr/include/boost/bind.hpp:436: error: no match for call to '(boost::_mfi::mf3, std::allocator<void> >, boost::function0<void>, std::allocator<void> >, const boost::shared_ptr, std::allocator<void> > > > >&, const boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, boost::reference_wrapper<Object> >) (boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >*&, boost::shared_ptr, std::allocator<void> > > > >&, boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, Object&)'
/usr/include/boost/bind/mem_fn_template.hpp:382: note: candidates are: R boost::_mfi::mf3::operator()(T*, A1, A2, A3) const [with R = void, T = boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >, A1 = const boost::shared_ptr, std::allocator<void> > > > >&, A2 = const boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, A3 = boost::reference_wrapper<Object>]
/usr/include/boost/bind/mem_fn_template.hpp:401: note: R boost::_mfi::mf3::operator()(T&, A1, A2, A3) const [with R = void, T = boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >, A1 = const boost::shared_ptr, std::allocator<void> > > > >&, A2 = const boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, A3 = boost::reference_wrapper<Object>]
Compilation exited abnormally with code 1 at Fri Apr 10 09:19:58
And here is the identical result with create_processor(boost::ref(Object)):
g++ -Wall -o test test.cc
/usr/include/boost/bind.hpp: In member function 'void boost::_bi::list4::operator()(boost::_bi::type<void>, F&, A&, int) [with F = boost::_mfi::mf3, std::allocator<void> >, boost::function0<void>, std::allocator<void> >, const boost::shared_ptr, std::allocator<void> > > > >&, const boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, boost::reference_wrapper<Object> >, A = boost::_bi::list0, A1 = boost::_bi::value, std::allocator<void> >, boost::function0<void>, std::allocator<void> >*>, A2 = boost::_bi::value, std::allocator<void> > > > > >, A3 = boost::_bi::value, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context>, A4 = boost::reference_wrapper<Object>]':
/usr/include/boost/bind/bind_template.hpp:20: instantiated from 'typename boost::_bi::result_traits::type boost::_bi::bind_t::operator()() [with R = void, F = boost::_mfi::mf3, std::allocator<void> >, boost::function0<void>, std::allocator<void> >, const boost::shared_ptr, std::allocator<void> > > > >&, const boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, boost::reference_wrapper<Object> >, L = boost::_bi::list4, std::allocator<void> >, boost::function0<void>, std::allocator<void> >*>, boost::_bi::value, std::allocator<void> > > > > >, boost::_bi::value, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context>, boost::reference_wrapper<Object> >]'
/usr/include/boost/function/function_template.hpp:152: instantiated from 'static void boost::detail::function::void_function_obj_invoker0::invoke(boost::detail::function::function_buffer&) [with FunctionObj = boost::_bi::bind_t, std::allocator<void> >, boost::function0<void>, std::allocator<void> >, const boost::shared_ptr, std::allocator<void> > > > >&, const boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, boost::reference_wrapper<Object> >, boost::_bi::list4, std::allocator<void> >, boost::function0<void>, std::allocator<void> >*>, boost::_bi::value, std::allocator<void> > > > > >, boost::_bi::value, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context>, boost::reference_wrapper<Object> > >, R = void]'
/usr/include/boost/function/function_template.hpp:931: instantiated from 'void boost::function0<R>::assign_to_a(Functor, Allocator) [with Functor = boost::_bi::bind_t, std::allocator<void> >, boost::function0<void>, std::allocator<void> >, const boost::shared_ptr, std::allocator<void> > > > >&, const boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, boost::reference_wrapper<Object> >, boost::_bi::list4, std::allocator<void> >, boost::function0<void>, std::allocator<void> >*>, boost::_bi::value, std::allocator<void> > > > > >, boost::_bi::value, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context>, boost::reference_wrapper<Object> > >, Allocator = std::allocator<void>, R = void]'
/usr/include/boost/function/function_template.hpp:733: instantiated from 'boost::function0<R>::function0(Functor, Allocator, typename boost::enable_if_c::type) [with Functor = boost::_bi::bind_t, std::allocator<void> >, boost::function0<void>, std::allocator<void> >, const boost::shared_ptr, std::allocator<void> > > > >&, const boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, boost::reference_wrapper<Object> >, boost::_bi::list4, std::allocator<void> >, boost::function0<void>, std::allocator<void> >*>, boost::_bi::value, std::allocator<void> > > > > >, boost::_bi::value, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context>, boost::reference_wrapper<Object> > >, Allocator = std::allocator<void>, R = void]'
/usr/include/boost/statechart/processor_container.hpp:112: instantiated from 'WorkItem boost::statechart::processor_container::create_processor(boost::weak_ptr >&, Scheduler&, Arg1) [with Processor = Test, Arg1 = boost::reference_wrapper<Object>, Scheduler = boost::statechart::fifo_scheduler, std::allocator<void> >, WorkItem = boost::function0<void>, Allocator = std::allocator<void>]'
/usr/include/boost/statechart/fifo_scheduler.hpp:63: instantiated from 'typename boost::statechart::processor_container, typename FifoWorker::work_item, Allocator>::processor_handle boost::statechart::fifo_scheduler::create_processor(Arg1) [with Processor = Test, Arg1 = boost::reference_wrapper<Object>, FifoWorker = boost::statechart::fifo_worker, Allocator = std::allocator<void>]'
test.cc:36: instantiated from here
/usr/include/boost/bind.hpp:436: error: no match for call to '(boost::_mfi::mf3, std::allocator<void> >, boost::function0<void>, std::allocator<void> >, const boost::shared_ptr, std::allocator<void> > > > >&, const boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, boost::reference_wrapper<Object> >) (boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >*&, boost::shared_ptr, std::allocator<void> > > > >&, boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, Object&)'
/usr/include/boost/bind/mem_fn_template.hpp:382: note: candidates are: R boost::_mfi::mf3::operator()(T*, A1, A2, A3) const [with R = void, T = boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >, A1 = const boost::shared_ptr, std::allocator<void> > > > >&, A2 = const boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, A3 = boost::reference_wrapper<Object>]
/usr/include/boost/bind/mem_fn_template.hpp:401: note: R boost::_mfi::mf3::operator()(T&, A1, A2, A3) const [with R = void, T = boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >, A1 = const boost::shared_ptr, std::allocator<void> > > > >&, A2 = const boost::statechart::processor_container, std::allocator<void> >, boost::function0<void>, std::allocator<void> >::processor_context&, A3 = boost::reference_wrapper<Object>]
Compilation exited abnormally with code 1 at Fri Apr 10 09:30:38