Smart pointers and member function pointers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • n2xssvv g02gfr12930

    Smart pointers and member function pointers

    Does anybody know of a smart pointer that supports 'operator->*'.

    As yet I've always had to use this type of expression ((*sp).*pFnc)()
    where

    sp .... Smart pointer to Obj
    pFnc .. Member function pointer ( void (Obj::*TYPE)(vo id) )

    but never with (sp->*pFnc)() which is possible for pointers.
  • John Harrison

    #2
    Re: Smart pointers and member function pointers

    n2xssvv g02gfr12930 wrote:[color=blue]
    > Does anybody know of a smart pointer that supports 'operator->*'.
    >
    > As yet I've always had to use this type of expression ((*sp).*pFnc)()
    > where
    >
    > sp .... Smart pointer to Obj
    > pFnc .. Member function pointer ( void (Obj::*TYPE)(vo id) )
    >
    > but never with (sp->*pFnc)() which is possible for pointers.[/color]

    This article might interest you.



    I guess this proposal never got approved.

    john

    Comment

    • n2xssvv g02gfr12930

      #3
      Re: Smart pointers and member function pointers

      John Harrison wrote:[color=blue]
      > n2xssvv g02gfr12930 wrote:
      >[color=green]
      >> Does anybody know of a smart pointer that supports 'operator->*'.
      >>
      >> As yet I've always had to use this type of expression ((*sp).*pFnc)()
      >> where
      >>
      >> sp .... Smart pointer to Obj
      >> pFnc .. Member function pointer ( void (Obj::*TYPE)(vo id) )
      >>
      >> but never with (sp->*pFnc)() which is possible for pointers.[/color]
      >
      >
      > This article might interest you.
      >
      > http://www.open-std.org/jtc1/sc22/wg...1996/N0831.pdf
      >
      > I guess this proposal never got approved.
      >
      > john[/color]

      The best I could come up with was to return an appropriate functor class
      like the template classes below allowing (sp->*pFnc)() to work.

      template <typename R,typename C,typename V1>
      class pmf1Functor
      {
      private:
      C *p;
      R (C::*pf)(V1);
      public:
      pmf1Functor(_Te st *_p, R (C::*_pf)(V1)) : p(_p),pf(_pf) {}
      R operator () (V1 inp) { return (p->*pf)(inp); }
      };

      template <typename C,typename V1>
      class pmf1Functor<voi d, C,V1>
      {
      private:
      C *p;
      void (C::*pf)(V1);
      public:
      pmf1Functor(_Te st *_p, void (C::*_pf)(V1)) : p(_p),pf(_pf) {}
      void operator () (V1 inp) { (p->*pf)(inp); }
      };

      template <typename R,typename C>
      class pmfFunctor
      {
      private:
      C *p;
      R (C::*pf)(void);
      public:
      pmfFunctor(_Tes t *_p, R (C::*_pf)(void) ) : p(_p),pf(_pf) {}
      R operator () (void) { return (p->*pf)(); }
      };

      template <typename C>
      class pmfFunctor<void , C>
      {
      private:
      C *p;
      void (C::*pf)(void);
      public:
      pmfFunctor(_Tes t *_p, void (C::*_pf)(void) ) : p(_p),pf(_pf) {}
      void operator () (void) { (p->*pf)(); }
      };

      Comment

      • n2xssvv g02gfr12930

        #4
        Re: Smart pointers and member function pointers

        n2xssvv g02gfr12930 wrote:[color=blue]
        > John Harrison wrote:
        >[color=green]
        >> n2xssvv g02gfr12930 wrote:
        >>[color=darkred]
        >>> Does anybody know of a smart pointer that supports 'operator->*'.
        >>>
        >>> As yet I've always had to use this type of expression ((*sp).*pFnc)()
        >>> where
        >>>
        >>> sp .... Smart pointer to Obj
        >>> pFnc .. Member function pointer ( void (Obj::*TYPE)(vo id) )
        >>>
        >>> but never with (sp->*pFnc)() which is possible for pointers.[/color]
        >>
        >>
        >>
        >> This article might interest you.
        >>
        >> http://www.open-std.org/jtc1/sc22/wg...1996/N0831.pdf
        >>
        >> I guess this proposal never got approved.
        >>
        >> john[/color]
        >
        >
        > The best I could come up with was to return an appropriate functor class
        > like the template classes below allowing (sp->*pFnc)() to work.
        >
        > template <typename R,typename C,typename V1>
        > class pmf1Functor
        > {
        > private:
        > C *p;
        > R (C::*pf)(V1);
        > public:[/color]
        replace _Test with C[color=blue]
        > pmf1Functor(_Te st *_p, R (C::*_pf)(V1)) : p(_p),pf(_pf) {}
        > R operator () (V1 inp) { return (p->*pf)(inp); }
        > };
        >
        > template <typename C,typename V1>
        > class pmf1Functor<voi d, C,V1>
        > {
        > private:
        > C *p;
        > void (C::*pf)(V1);
        > public:[/color]
        replace _Test with C[color=blue]
        > pmf1Functor(_Te st *_p, void (C::*_pf)(V1)) : p(_p),pf(_pf) {}
        > void operator () (V1 inp) { (p->*pf)(inp); }
        > };
        >
        > template <typename R,typename C>
        > class pmfFunctor
        > {
        > private:
        > C *p;
        > R (C::*pf)(void);
        > public:[/color]
        replace _Test with C[color=blue]
        > pmfFunctor(_Tes t *_p, R (C::*_pf)(void) ) : p(_p),pf(_pf) {}
        > R operator () (void) { return (p->*pf)(); }
        > };
        >
        > template <typename C>
        > class pmfFunctor<void , C>
        > {
        > private:
        > C *p;
        > void (C::*pf)(void);
        > public:[/color]
        replace _Test with C[color=blue]
        > pmfFunctor(_Tes t *_p, void (C::*_pf)(void) ) : p(_p),pf(_pf) {}
        > void operator () (void) { (p->*pf)(); }
        > };[/color]

        With the minor corrections shown sp->*pFnc; will now return a functor
        which then calls member pointer function from (sp->*pf)();

        JB

        Comment

        Working...