Re: [Boost-users] signals/slots and boost::functions
For those interested, It appears the reason was because of a compiler error I hit, and didn't ask about, or really worry how to resolve it. :-/ Function declaration: typedef boost::function < VSSP ( std::string, EncodingEnum) > CreateTypeFunc; bool ElementBase::disconnectCreateTypeSignal(const CreateTypeFunc& slot) { LOG4CXX_DEBUG(logger_, "disconnectCreateTypeSignal in"); bool retValue = false; createTypeSignal_.disconnect(slot); <snip!> } Error: (apologies for the length) c:\Program Files\boost\boost_1_35_0\boost\signals\signal_template.hpp(242) : error C2666: 'boost::operator`=='' : 4 over loads have similar conversions; c:\Program Files\boost\boost_1_35_0\boost\function\function_base.hpp(669): could be 'boo st::enable_if_c<B,T>::type boost::operator ==<boost::signal2<R,T1,T2,Combiner,Group,GroupCompare,SlotFunction>::slo t_fun ction_type>(Functor,const boost::function_base &) with [B=true,T=bool,R=boost::detail::function_traits_helper<boost::add _pointer<boost::shared_ptr<model::VariantStorage> (std::string,model::EncodingEnum::EncodingEnum)>::type>::result_type,T 1=boost::detail::function_traits_helper<boost::add_pointer<boost::shared _ptr<model::VariantStorage> (std::string,model:: EncodingEnum::EncodingEnum)>::type>::arg1_type,T2=boost::detail::functio n_traits_helper<boost::add_pointer<boost::shared _ptr<model::VariantStorage> (std::string,model::EncodingEnum::EncodingEnum)>::type>::arg2_type,Combi ner=boost::last_valu e<boost::detail::function_traits_helper<boost::add_pointer<boost::shared _ptr<model::VariantStorage> (std::string,model:: EncodingEnum::EncodingEnum)>::type>::result_type>,Group=int,GroupCompare =std::less<int>,SlotFunction=boost::function<mod el::VariantStorageSharedPtr (std::string,model::EncodingEnum::EncodingEnum)>,Functor=boost::signal2< boost::detail::funct ion_traits_helper<boost::add_pointer<boost::shared_ptr<model::VariantSto rage> (std::string,model::EncodingEnum::Encoding Enum)>::type>::result_type,boost::detail::function_traits_helper<boost:: add_pointer<boost::shared_ptr<model::VariantStor age> (std::string,model::EncodingEnum::EncodingEnum)>::type>::arg1_type,boost ::detail::function_traits_helper<boost::add _pointer<boost::shared_ptr<model::VariantStorage> (std::string,model::EncodingEnum::EncodingEnum)>::type>::arg2_type,boo st::last_value<boost::detail::function_traits_helper<boost::add_pointer< boost::shared_ptr<model::VariantStorage> (std::s tring,model::EncodingEnum::EncodingEnum)>::type>::result_type>,int,std:: less<int>,boost::function<model::VariantStorageS haredPtr (std::string,model::EncodingEnum::EncodingEnum)>>::slot_function_type]'; c:\Program Files\boost\boost_1_35_0\bo ost\function\function_base.hpp(660): or 'boost::enable_if_c<B,T>::type boost::operator ==<Function>(const boost::f unction_base &,Functor) with [B=true,T=bool,Function=model::ElementBase::CreateTypeFunc,Functor=model ::ElementBase::Crea teTypeFunc]'; c:\Program Files\boost\boost_1_35_0\boost\function\function_template.hpp(832): or 'void boost::opera tor ==<R,T0,T1,Allocator>(const boost::function2<R,T0,T1,Allocator> &,const boost::function2<R,T0,T1,Allocator> &) with [R=model::VariantStorageSharedPtr,T0=std::string,T1=model::EncodingEnum: :EncodingEnum,Allocator=std::allocator<void>]'; or 'built-in C++ operator==(boost::function2<R,T0,T1,Allocator>::safe_bool with [R=model::VariantStorageSharedPtr, T0=std::string,T1=model::EncodingEnum::EncodingEnum,Allocator=std::alloc ator<void>], boost::function2<R,T0,T1,Allocator> ::safe_bool with [R=model::VariantStorageSharedPtr,T0=std::string,T1=model::EncodingEnum: :EncodingEnum,Allocator=std::al locator<void>])'; while trying to match the argument list '(boost::signal2<R,T1,T2,Combiner,Group,GroupCompare,SlotFunct ion>::slot_function_type with [R=boost::detail::function_traits_helper<boost::add_pointer<boost::share d_ptr<model::Varia ntStorage> (std::string,model::EncodingEnum::EncodingEnum)>::type>::result_type,T1= boost::detail::function_traits_helper <boost::add_pointer<boost::shared_ptr<model::VariantStorage> (std::string,model::EncodingEnum::EncodingEnum)>::type>::ar g1_type,T2=boost::detail::function_traits_helper<boost::add_pointer<boos t::shared_ptr<model::VariantStorage> (std::strin g,model::EncodingEnum::EncodingEnum)>::type>::arg2_type,Combiner=boost:: last_value<boost::detail::function_traits_helper <boost::add_pointer<boost::shared_ptr<model::VariantStorage> (std::string,model::EncodingEnum::EncodingEnum)>::type>::re sult_type>,Group=int,GroupCompare=std::less<int>,SlotFunction=boost::fun ction<model::VariantStorageSharedPtr (std::strin g,model::EncodingEnum::EncodingEnum)>], const model::ElementBase::CreateTypeFunc)'; c:\Program Files\boost\boost_1_35_0\ boost\signals\signal_template.hpp(224) : see reference to function template instantiation 'void boost::signal2<R,T1,T2,C ombiner,Group,GroupCompare,SlotFunction>::do_disconnect<T>(const Function &,boost::mpl::bool_<C_>) with [R=boost::detail ::function_traits_helper<boost::add_pointer<boost::shared_ptr<model::Var iantStorage> (std::string,model::EncodingEnum::E ncodingEnum)>::type>::result_type,T1=boost::detail::function_traits_help er<boost::add_pointer<boost::shared_ptr<model::V ariantStorage> (std::string,model::EncodingEnum::EncodingEnum)>::type>::arg1_type,T2=bo ost::detail::function_traits_help er<boost::add_pointer<boost::shared_ptr<model::VariantStorage> (std::string,model::EncodingEnum::EncodingEnum)>::type>:: arg2_type,Combiner=boost::last_value<boost::detail::function_traits_help er<boost::add_pointer<boost::shared_ptr<model::V ariantStorage> (std::string,model::EncodingEnum::EncodingEnum)>::type>::result_type>,Gr oup=int,GroupCompare=std::less<in t>,SlotFunction=boost::function<model::VariantStorageSharedPtr (std::string,model::EncodingEnum::EncodingEnum)>,T=model: :ElementBase::CreateTypeFunc,Function=model::ElementBase::CreateTypeFunc ,C_=false]' being compiled; c:\Documents and Set tings\td26134\Desktop\trunk1\src\model\ElementBase.cpp(440) : see reference to function template instantiation 'void boo st::signal2<R,T1,T2,Combiner,Group,GroupCompare,SlotFunction>::disconnec t<model::ElementBase::CreateTypeFunc>(const T &) with [R=boost::detail::function_traits_helper<boost::add_pointer<boost::share d_ptr<model::VariantStorage> (std::string, model::EncodingEnum::EncodingEnum)>::type>::result_type,T1=boost::detail ::function_traits_helper<boost::add_pointer<boos t::shared_ptr<model::VariantStorage> (std::string,model::EncodingEnum::EncodingEnum)>::type>::arg1_type,T2=bo ost::detail ::function_traits_helper<boost::add_pointer<boost::shared_ptr<model::Var iantStorage> (std::string,model::EncodingEnum::E ncodingEnum)>::type>::arg2_type,Combiner=boost::last_value<boost::detail ::function_traits_helper<boost::add_pointer<boos t::shared_ptr<model::VariantStorage> (std::string,model::EncodingEnum::EncodingEnum)>::type>::result_type>,Gr oup=int,Gro upCompare=std::less<int>,SlotFunction=boost::function<model::VariantStor ageSharedPtr (std::string,model::EncodingEnum::E ncodingEnum)>,T=model::ElementBase::CreateTypeFunc]' being compiled scons: *** [build_dir\Windows\src-model\ElementBase.obj] Error 2
AMDG david.weber@l-3com.com wrote:
For those interested, It appears the reason was because of a compiler error I hit, and didn't ask about, or really worry how to resolve it. :-/
Function declaration:
typedef boost::function < VSSP ( std::string, EncodingEnum) > CreateTypeFunc;
bool ElementBase::disconnectCreateTypeSignal(const CreateTypeFunc& slot) { LOG4CXX_DEBUG(logger_, "disconnectCreateTypeSignal in"); bool retValue = false;
createTypeSignal_.disconnect(slot);
Ah. If you can somehow know what type slot holds, then it would work. See http://www.boost.org/doc/html/function/faq.html#id2914032 In Christ, Steven Watanabe
Ah. If you can somehow know what type slot holds, then it would work. See http://www.boost.org/doc/html/function/faq.html#id2914032
Hrm. I read it, and understand the reasons why, but then I read this: "The Signals library has a way around this." I was wondering if you had any insight, and could elaborate further, as this is functionality that would make our implementation significantly simpler. We do have a well-defined function prototype, and all the code is being written as we speak, so it's simple enough to enforce certain restrictions to gain the functionality (if possible).
AMDG david.weber@l-3com.com wrote:
Ah. If you can somehow know what type slot holds, then it would work. See http://www.boost.org/doc/html/function/faq.html#id2914032
Hrm. I read it, and understand the reasons why, but then I read this: "The Signals library has a way around this."
I was wondering if you had any insight, and could elaborate further, as this is functionality that would make our implementation significantly simpler. We do have a well-defined function prototype, and all the code is being written as we speak, so it's simple enough to enforce certain restrictions to gain the functionality (if possible)
You have to know what the real type of the slot is when you call disconnect. Unless you are passing a single type of function pointer, you can template the connect and disconnect functions. Here's an extremely simplified example. #include <boost/signal.hpp> #include <boost/bind.hpp> #include <iostream> boost::signal<void()> sig; template<class F> void connect(F f) { sig.connect(f); } template<class F> void disconnect(F f) { sig.disconnect(f); } struct printer { typedef void result_type; void operator()(int i) const { std::cout << i << std::endl; } }; bool operator==(const printer&, const printer&) { return(true); } int main() { connect(boost::bind(printer(), 1)); sig(); disconnect(boost::bind(printer(), 1)); sig(); } In Christ, Steven Watanabe
participants (2)
-
david.weber@l-3com.com
-
Steven Watanabe