Re: [Boost-users] WG: defining a function<>-object with a returnvalue of the same type (recursive declaration)
Hmm - I would use boost::function instead of declaring a function-pointer object by myself. Regards, Oliver
On 5/2/06, Oliver.Kowalke@qimonda.com
wrote: how can I define a function<> object which returns a value of the same type:
This was taken from GotW article 57: http://www.gotw.ca/gotw//057.htm
struct FuncPtr_; typedef FuncPtr_ (*FuncPtr)();
struct FuncPtr_ { FuncPtr_( FuncPtr pp ) : p( pp ) { } operator FuncPtr() { return p; } FuncPtr p; };
Now we can declare, define, and use f() naturally:
FuncPtr_ f() { return f; } // natural return syntax
int main() { FuncPtr p = f(); // natural usage syntax p(); }
HTH,
Michael Fawcett _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 5/3/06, Oliver.Kowalke@qimonda.com
Hmm - I would use boost::function instead of declaring a function-pointer object by myself.
Go for it. I just pasted the code from Herb Sutter's article that showed how to accomplish what you wanted with a function object and a function pointer. You could probably move that into a function<> if that's what you need. -Michael Fawcett
participants (2)
-
Michael Fawcett
-
Oliver.Kowalke@qimonda.com