Smart pointers and member function pointers

Discussion in 'C++' started by n2xssvv g02gfr12930, Nov 26, 2005.

  1. 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)(void) )

    but never with (sp->*pFnc)() which is possible for pointers.
     
    n2xssvv g02gfr12930, Nov 26, 2005
    #1
    1. Advertising

  2. n2xssvv g02gfr12930 wrote:
    > 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)(void) )
    >
    > but never with (sp->*pFnc)() which is possible for pointers.


    This article might interest you.

    http://www.open-std.org/jtc1/sc22/wg21/docs/papers/1996/N0831.pdf

    I guess this proposal never got approved.

    john
     
    John Harrison, Nov 26, 2005
    #2
    1. Advertising

  3. John Harrison wrote:
    > n2xssvv g02gfr12930 wrote:
    >
    >> 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)(void) )
    >>
    >> but never with (sp->*pFnc)() which is possible for pointers.

    >
    >
    > This article might interest you.
    >
    > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/1996/N0831.pdf
    >
    > I guess this proposal never got approved.
    >
    > john


    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(_Test *_p, R (C::*_pf)(V1)) : p(_p),pf(_pf) {}
    R operator () (V1 inp) { return (p->*pf)(inp); }
    };

    template <typename C,typename V1>
    class pmf1Functor<void, C,V1>
    {
    private:
    C *p;
    void (C::*pf)(V1);
    public:
    pmf1Functor(_Test *_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(_Test *_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(_Test *_p, void (C::*_pf)(void)) : p(_p),pf(_pf) {}
    void operator () (void) { (p->*pf)(); }
    };
     
    n2xssvv g02gfr12930, Nov 26, 2005
    #3
  4. n2xssvv g02gfr12930 wrote:
    > John Harrison wrote:
    >
    >> n2xssvv g02gfr12930 wrote:
    >>
    >>> 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)(void) )
    >>>
    >>> but never with (sp->*pFnc)() which is possible for pointers.

    >>
    >>
    >>
    >> This article might interest you.
    >>
    >> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/1996/N0831.pdf
    >>
    >> I guess this proposal never got approved.
    >>
    >> john

    >
    >
    > 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:

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

    replace _Test with C
    > pmf1Functor(_Test *_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:

    replace _Test with C
    > pmfFunctor(_Test *_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:

    replace _Test with C
    > pmfFunctor(_Test *_p, void (C::*_pf)(void)) : p(_p),pf(_pf) {}
    > void operator () (void) { (p->*pf)(); }
    > };


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

    JB
     
    n2xssvv g02gfr12930, Nov 27, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Newsgroup - Ann
    Replies:
    5
    Views:
    655
    John Carson
    Jul 30, 2003
  2. Fraser Ross
    Replies:
    4
    Views:
    1,093
    Fraser Ross
    Aug 14, 2004
  3. MotoK
    Replies:
    59
    Views:
    1,917
    Keith Thompson
    Sep 15, 2006
  4. Hamish
    Replies:
    3
    Views:
    605
    Alf P. Steinbach
    Jan 25, 2008
  5. paul
    Replies:
    8
    Views:
    744
    Alf P. Steinbach
    Apr 30, 2009
Loading...

Share This Page