|
Boost Users : |
Subject: [Boost-users] How to connect to any boost::signal with a void returning function?
From: Sak (mailjsv_at_[hidden])
Date: 2012-08-14 07:01:31
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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net