Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Smart pointers and member function pointers

Reply
Thread Tools

Smart pointers and member function pointers

 
 
n2xssvv g02gfr12930
Guest
Posts: n/a
 
      11-26-2005
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.
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      11-26-2005
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/wg...1996/N0831.pdf

I guess this proposal never got approved.

john
 
Reply With Quote
 
 
 
 
n2xssvv g02gfr12930
Guest
Posts: n/a
 
      11-26-2005
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/wg...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)(); }
};
 
Reply With Quote
 
n2xssvv g02gfr12930
Guest
Posts: n/a
 
      11-27-2005
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/wg...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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
static member functions vs. member function pointers paul C++ 8 04-30-2009 11:03 AM
Member function pointers to member functions with default arguments Hamish C++ 3 01-25-2008 06:46 AM
Smart Pointers: Is there something similar to smart pointers in C? MotoK C Programming 59 09-15-2006 07:03 PM
pointer to member function and pointer to constant member function Fraser Ross C++ 4 08-14-2004 06:00 PM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM



Advertisments