How to connect to any boost::signal with a void returning function?

Hi All, I'm trying to connect a simple void returning function to multiple signals of varying signature, I can see some references mentioning that it's possible using boost::lambda::bind and boost::spirit::bind, But I keep getting compilation errors, Is there something wrong with the following code? Or is there a better way to do it? or is it not possible to do? Boost version: Release 1.46.1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #include <boost/signals2.hpp>#include <boost/lambda/bind.hpp>#include <boost/lambda/lambda.hpp> #include <boost/spirit/include/phoenix.hpp> using namespace boost::signals2; void func() { printf("Func called!"); } main() { signal<int(int)> sig; sig.connect( (boost::lambda::bind(func), 1) ); // Compilation error // sig.connect( (boost::phoenix::bind(func), 1) ); // Compilation error } I'm getting the following compilation errors when using boost::lambda::bind: 1 2 3 4 5 /opt/include/boost/signals2/detail/slot_template.hpp: In member function ‘void boost::signals2::slot1<R, T1, SlotFunction>::init_slot_function(const F&) [with F = int, R = int, T1 = int, SlotFunction = boost::function<int(int)>]’: /opt/include/boost/signals2/detail/slot_template.hpp:81:9: instantiated from ‘boost::signals2::slot1<R, T1, SlotFunction>::slot1(const F&) [with F = int, R = int, T1 = int, SlotFunction = boost::function<int(int)>]’ hello-world-example.cpp:15:51: instantiated from here /opt/include/boost/signals2/detail/slot_template.hpp:156:9: error: invalid conversion from ‘int’ to ‘boost::function<int(int)>::clear_type*’ [-fpermissive] /opt/include/boost/function/function_template.hpp:1110:14: error: initializing argument 1 of ‘boost::function<R(T0)>::self_type& boost::function<R(T0)>::operator=(boost::function<R(T0)>::clear_type*) [with R = int, T0 = int, boost::function<R(T0)>::self_type = boost::function<int(int)>]’ [-fpermissive] I'm getting the following compilation errors when using boost::phoenix::bind: 1 2 3 4 5 /opt/include/boost/function/function_template.hpp: In static member function ‘static R boost::detail::function::function_obj_invoker1<FunctionObj, R, T0>::invoke(boost::detail::function::function_buffer&, T0) [with FunctionObj = boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::detail::function_eval<0>, boost::fusion::vector<boost::phoenix::value<boost::phoenix::detail::function_ptr<0, void, void (*)()> >, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >, R = int, T0 = int]’: /opt/include/boost/function/function_template.hpp:913:60: instantiated from ‘void boost::function1<R, T1>::assign_to(Functor) [with Functor = boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::detail::function_eval<0>, boost::fusion::vector<boost::phoenix::value<boost::phoenix::detail::function_ptr<0, void, void (*)()> >, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >, R = int, T0 = int]’ /opt/include/boost/function/function_template.hpp:722:7: instantiated from ‘boost::function1<R, T1>::function1(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::detail::function_eval<0>, boost::fusion::vector<boost::phoenix::value<boost::phoenix::detail::function_ptr<0, void, void (*)()> >, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >, R = int, T0 = int, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’ /opt/include/boost/function/function_template.hpp:1064:16: instantiated from ‘boost::function<R(T0)>::function(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::detail::function_eval<0>, boost::fusion::vector<boost::phoenix::value<boost::phoenix::detail::function_ptr<0, void, void (*)()> >, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >, R = int, T0 = int, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’ /opt/include/boost/function/function_template.hpp:1105:5: instantiated from ‘typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, boost::function<R(T0)>&>::type boost::function<R(T0)>::operator=(Functor) [with Functor = boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::detail::function_eval<0>, boost::fusion::vector<boost::phoenix::value<boost::phoenix::detail::function_ptr<0, void, void (*)()> >, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >, R = int, T0 = int, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, boost::function<R(T0)>&>::type = boost::function<int(int)>&]’ /opt/include/boost/signals2/detail/slot_template.hpp:156:9: instantiated from ‘void boost::signals2::slot1<R, T1, SlotFunction>::init_slot_function(const F&) [with F = boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::detail::function_eval<0>, boost::fusion::vector<boost::phoenix::value<boost::phoenix::detail::function_ptr<0, void, void (*)()> >, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >, R = int, T1 = int, SlotFunction = boost::function<int(int)>]’ /opt/include/boost/signals2/detail/slot_template.hpp:81:9: instantiated from ‘boost::signals2::slot1<R, T1, SlotFunction>::slot1(const F&) [with F = boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::detail::function_eval<0>, boost::fusion::vector<boost::phoenix::value<boost::phoenix::detail::function_ptr<0, void, void (*)()> >, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >, R = int, T1 = int, SlotFunction = boost::function<int(int)>]’ ../../../examples/hello-world/hello-world-example.cpp:16:51: instantiated from here /opt/include/boost/function/function_template.hpp:132:42: error: void value not ignored as it ought to be /opt/include/boost/function/function_template.hpp:133:9: error: control reaches end of non-void function [-Werror=return-type] Many thanks, Sak

I'm trying to connect a simple void returning function to multiple signals of varying signature, I can see some references mentioning that it's possible using boost::lambda::bind and boost::spirit::bind, But I keep getting compilation errors, Is there something wrong with the following code? Or is there a better way to do it? or is it not possible to do?
Sak, I have no idea what is a spirit or a phoenix, but your code compiles fine on my computer except for "undefined printf" which I commented out: gcc 4.5.3 boost 1.48 Chris

Hi Chris, Doh, yes gave a try with boost 1.49 and it builds ok. Thanks, Sak On Tue, Aug 14, 2012 at 5:01 PM, Chris Stankevitz <chrisstankevitz@gmail.com
wrote:
I'm trying to connect a simple void returning function to multiple signals
of varying signature, I can see some references mentioning that it's possible using boost::lambda::bind and boost::spirit::bind, But I keep getting compilation errors, Is there something wrong with the following code? Or is there a better way to do it? or is it not possible to do?
Sak,
I have no idea what is a spirit or a phoenix, but your code compiles fine on my computer except for "undefined printf" which I commented out:
gcc 4.5.3 boost 1.48
Chris
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Tue, Aug 14, 2012 at 09:01:22AM -0700, Chris Stankevitz wrote:
I'm trying to connect a simple void returning function to multiple signals of varying signature, I can see some references mentioning that it's possible using boost::lambda::bind and boost::spirit::bind, But I keep getting compilation errors, Is there something wrong with the following code? Or is there a better way to do it? or is it not possible to do?
I have no idea what is a spirit or a phoenix, but your code compiles fine on my computer except for "undefined printf" which I commented out:
Assumedly he meant boost::phoenix::bind there, not 'spirit'. Boost.Phoenix is a library for composing functions and more, well more powerful than Boost.Bind and Boost.Lambda, originating from within Boost.Spirit, nowadays being a proper separate library. Boost.Spirit is a parser/generator library, full of goodness. -- Lars Viklund | zao@acc.umu.se
participants (3)
-
Chris Stankevitz
-
Lars Viklund
-
Sak