Re: sigc::mem_fun and Glib::RefPtr
- From: Horváth Imre <blemidon gmail com>
- To: Kjell Ahlstedt <kjell ahlstedt bredband net>
- Cc: gtkmm-list gnome org
- Subject: Re: sigc::mem_fun and Glib::RefPtr
- Date: Fri, 05 Oct 2012 10:42:26 +0200
Thank you, it works!
Regards,
Imre Horvath
2012. 10. 5, péntek keltezéssel 10.38-kor Kjell Ahlstedt ezt írta:
> All this seems incredibly complicated. Bug 495762 mentions an easier
> way. See especially comment 9.
>
> https://bugzilla.gnome.org/show_bug.cgi?id=495762#c9
>
> It's cryptic. I haven't tested it myself, but I suppose someone else has.
>
> Glib::RefPtr<MyClass> c;
> ...
> button.signal_clicked().connect(sigc::mem_fun(c.operator->(),
> &MyClass::on_button));
>
> Kjell
>
> 2012-10-05 09:25, Horváth Imre skrev:
> > Thank you for your answer
> >
> > I tried to replace std::shared_ptr with Glib::RefPtr, but it didn't
> > worked for me.
> >
> > #include <memory>
> > #include <sigc++/sigc++.h>
> > #include <glibmm.h>
> >
> > namespace sigc
> > {
> > template <class T>
> > struct dereference_trait<Glib::RefPtr<T> >
> > { typedef T& type; };
> >
> > template <class T>
> > struct dereference_trait<Glib::RefPtr<T>& >
> > { typedef T& type; };
> >
> > }
> >
> > class MyClass : public Glib::Object
> > {
> > public:
> > MyClass()
> > : Glib::ObjectBase(typeid(MyClass))
> > {
> > }
> > void on_button()
> > {
> > }
> > };
> >
> > int main()
> > {
> > Glib::RefPtr<MyClass> c(new MyClass);
> >
> > sigc::slot<void> f =
> > sigc::bind(sigc::group(sigc::mem_fun(&MyClass::on_button),
> > *sigc::_1),
> > c);
> > f();
> >
> >
> > return 0;
> > }
> >
> >
> > g++ main.cpp `pkg-config --libs --cflags sigc++-2.0 glibmm-2.4` -std=c
> > ++0x
> >
> >
> > In file included from /usr/include/sigc++-2.0/sigc
> > ++/adaptors/lambda/lambda.h:25,
> > from /usr/include/sigc++-2.0/sigc
> > ++/adaptors/adaptors.h:30,
> > from /usr/include/sigc++-2.0/sigc++/sigc++.h:26,
> > from main.cpp:2:
> > /usr/include/sigc++-2.0/sigc++/adaptors/lambda/operator.h: In static
> > member function ‘static typename
> > sigc::lambda_action_unary_deduce_result_type<sigc::unary_other<sigc::dereference>, T_test>::type sigc::lambda_action_unary<sigc::unary_other<sigc::dereference> >::do_action(T_arg) [with T_arg = Glib::RefPtr<MyClass>&]’:
> > /usr/include/sigc++-2.0/sigc++/adaptors/lambda/operator.h:788:
> > instantiated from ‘typename sigc::lambda_operator_unary<T_action,
> > T_type>::deduce_result_type<T_arg1, void, void, void, void, void,
> > void>::type sigc::lambda_operator_unary<T_action,
> > T_type>::operator()(T_arg1) const [with T_arg1 = Glib::RefPtr<MyClass>&,
> > T_action = sigc::unary_other<sigc::dereference>, T_type =
> > sigc::internal::lambda_select1]’
> > /usr/include/sigc++-2.0/sigc++/adaptors/lambda/base.h:70: instantiated
> > from ‘typename sigc::internal::lambda_core<T_type,
> > true>::deduce_result_type<T_arg1, void, void, void, void, void,
> > void>::type sigc::internal::lambda_core<T_type,
> > true>::operator()(T_arg1) const [with T_arg1 = Glib::RefPtr<MyClass>&,
> > T_type =
> > sigc::lambda_operator_unary<sigc::unary_other<sigc::dereference>,
> > sigc::internal::lambda_select1>]’
> > /usr/include/sigc++-2.0/sigc++/adaptors/lambda/group.h:93:
> > instantiated from ‘typename sigc::lambda_group1<T_functor,
> > T_type1>::deduce_result_type<T_arg1, void, void, void, void, void,
> > void>::type sigc::lambda_group1<T_functor, T_type1>::operator()(T_arg1)
> > const [with T_arg1 = Glib::RefPtr<MyClass>&, T_functor =
> > sigc::mem_functor0<void, MyClass>, T_type1 =
> > sigc::lambda<sigc::lambda_operator_unary<sigc::unary_other<sigc::dereference>, sigc::internal::lambda_select1> >]’
> > /usr/include/sigc++-2.0/sigc++/adaptors/lambda/base.h:70: instantiated
> > from ‘typename sigc::internal::lambda_core<T_type,
> > true>::deduce_result_type<T_arg1, void, void, void, void, void,
> > void>::type sigc::internal::lambda_core<T_type,
> > true>::operator()(T_arg1) const [with T_arg1 = Glib::RefPtr<MyClass>&,
> > T_type = sigc::lambda_group1<sigc::mem_functor0<void, MyClass>,
> > sigc::lambda<sigc::lambda_operator_unary<sigc::unary_other<sigc::dereference>, sigc::internal::lambda_select1> > >]’
> > /usr/include/sigc++-2.0/sigc++/adaptors/bind.h:1110: instantiated from
> > ‘typename sigc::adapts<T_functor>::adaptor_type::result_type
> > sigc::bind_functor<-0x00000000000000001, T_functor, T_type1, sigc::nil,
> > sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>::operator()()
> > [with T_functor =
> > sigc::lambda<sigc::lambda_group1<sigc::mem_functor0<void, MyClass>,
> > sigc::lambda<sigc::lambda_operator_unary<sigc::unary_other<sigc::dereference>, sigc::internal::lambda_select1> > > >, T_type1 = Glib::RefPtr<MyClass>]’
> > /usr/include/sigc++-2.0/sigc++/functors/slot.h:103: instantiated from
> > ‘static T_return sigc::internal::slot_call0<T_functor,
> > T_return>::call_it(sigc::internal::slot_rep*) [with T_functor =
> > sigc::bind_functor<-0x00000000000000001,
> > sigc::lambda<sigc::lambda_group1<sigc::mem_functor0<void, MyClass>,
> > sigc::lambda<sigc::lambda_operator_unary<sigc::unary_other<sigc::dereference>, sigc::internal::lambda_select1> > > >, Glib::RefPtr<MyClass>, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>, T_return = void]’
> > /usr/include/sigc++-2.0/sigc++/functors/slot.h:110: instantiated from
> > ‘static void* (* sigc::internal::slot_call0<T_functor,
> > T_return>::address())(void*) [with T_functor =
> > sigc::bind_functor<-0x00000000000000001,
> > sigc::lambda<sigc::lambda_group1<sigc::mem_functor0<void, MyClass>,
> > sigc::lambda<sigc::lambda_operator_unary<sigc::unary_other<sigc::dereference>, sigc::internal::lambda_select1> > > >, Glib::RefPtr<MyClass>, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>, T_return = void]’
> > /usr/include/sigc++-2.0/sigc++/functors/slot.h:454: instantiated from
> > ‘sigc::slot0<T_return>::slot0(const T_functor&) [with T_functor =
> > sigc::bind_functor<-0x00000000000000001,
> > sigc::lambda<sigc::lambda_group1<sigc::mem_functor0<void, MyClass>,
> > sigc::lambda<sigc::lambda_operator_unary<sigc::unary_other<sigc::dereference>, sigc::internal::lambda_select1> > > >, Glib::RefPtr<MyClass>, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>, T_return = void]’
> > /usr/include/sigc++-2.0/sigc++/functors/slot.h:1130: instantiated from
> > ‘sigc::slot<T_return, sigc::nil, sigc::nil, sigc::nil, sigc::nil,
> > sigc::nil, sigc::nil, sigc::nil>::slot(const T_functor&) [with T_functor
> > = sigc::bind_functor<-0x00000000000000001,
> > sigc::lambda<sigc::lambda_group1<sigc::mem_functor0<void, MyClass>,
> > sigc::lambda<sigc::lambda_operator_unary<sigc::unary_other<sigc::dereference>, sigc::internal::lambda_select1> > > >, Glib::RefPtr<MyClass>, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>, T_return = void]’
> > main.cpp:42: instantiated from here
> > /usr/include/sigc++-2.0/sigc++/adaptors/lambda/operator.h:489: error: no
> > match for ‘operator*’ in ‘*_Aa’
> >
> >
> >
> > Regards,
> > Imre
> >
> > 2012. 10. 4, csütörtök keltezéssel 22.07-kor klaus triendl ezt írta:
> >> Am Thu, 04 Oct 2012 18:31:17 +0200
> >> schrieb Horváth Imre <blemidon gmail com>:
> >>
> >>> Hi!
> >>>
> >>> IS there a solution to use Glib::RefPtr with sigc::mem_fun?
> >>> Example:
> >>>
> >>> Glib::RefPtr<MyClass> c;
> >>> ...
> >>> button.signal_clicked().connect(sigc::mem_fun(c,
> >>> &MyClass::on_button));
> >> yes, there is, by using sigc lambdas. a little complicated but it works.
> >>
> >> short example program (replace std::shared_ptr by Glib::RefPtr):
> >>
> >> <code>
> >> #include <memory>
> >> #include <sigc++/sigc++.h>
> >>
> >>
> >> namespace sigc
> >> {
> >>
> >> // the partially specialized struct dereference_trait is essential,
> >> // otherwise sigc can't deduce the return type from expression *sigc::_1
> >>
> >> template <class T>
> >> struct dereference_trait<std::shared_ptr<T> >
> >> { typedef T type; };
> >>
> >> template <class T>
> >> struct dereference_trait<std::shared_ptr<T>& >
> >> { typedef T type; };
> >>
> >> }
> >>
> >>
> >> struct MyClass
> >> {
> >> void on_button()
> >> {
> >> }
> >> };
> >>
> >>
> >> int main()
> >> {
> >> std::shared_ptr<MyClass> c(new MyClass);
> >>
> >> sigc::slot<void> f =
> >> sigc::bind(sigc::group(sigc::mem_fun(&MyClass::on_button),
> >> *sigc::_1),
> >> c);
> >> f();
> >>
> >>
> >> return 0;
> >> }
> >> </code>
> >>
> >> if you have variadic templates available you could pack the
> >> sigc::bind(sigc::group()) part into a factory function, in order to
> >> make the code more readable.
> >>
> >>
> >>
> >> greetings,
> >> klaus
> >
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]