C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Smart pointers and member function pointers

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
n2xssvv g02gfr12930
Guest





PostPosted: Sat Nov 26, 2005 10:05 am    Post subject: Smart pointers and member function pointers Reply with quote



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.
Back to top
John Harrison
Guest





PostPosted: Sat Nov 26, 2005 12:52 pm    Post subject: Re: Smart pointers and member function pointers Reply with quote



n2xssvv g02gfr12930 wrote:
Quote:
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

Back to top
n2xssvv g02gfr12930
Guest





PostPosted: Sat Nov 26, 2005 10:55 pm    Post subject: Re: Smart pointers and member function pointers Reply with quote



John Harrison wrote:
Quote:
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)(); }
};

Back to top
n2xssvv g02gfr12930
Guest





PostPosted: Sun Nov 27, 2005 10:51 am    Post subject: Re: Smart pointers and member function pointers Reply with quote

n2xssvv g02gfr12930 wrote:
Quote:
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 {
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 {
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

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.