Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::result_of template
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2012-04-13 12:15:13


On Fri, Apr 13, 2012 at 7:35 AM, John M. Dlugosz <mpbecey7gu_at_[hidden]>wrote:

> The plot thickens:
>
> class Universe : std::tr1::enable_shared_from_**this<Universe> {
> const int answer;
> public:
> Universe (int a) : answer(a) {}
> std::string get_answer() const;
> void get_nothing() {}
> virtual void blahblah(); // !!!
> };
>
>
>
>
> Universe u1(42);
> foo (&Universe::get_answer, &u1);
>
>
> Regarding my previous post on the definitions of foo,
> if the class inherits from enable_shared_from this *and* contains a
> virtual function, then this call to foo doesn't work, giving funny template
> errors in boost::result_of.
>

It's really not so funny :)

&Universe::get_answer is not an object supporting function-call syntax, so
using boost::result_of to query the result of function application is,
strictly speaking, meaningless. Boost.Bind happens to have special support
for pointers-to-member-functions, but not all Boost libraries do, since
it's a relatively simple matter to wrap the pointer in boost::mem_fun
(note: I've actually forgotten the precise name).

Regarding your initial message, on how to generically get the result type
of a function object *or* a pointer-to-member-function, you'd need to
create your own metafunction which dispatches to boost::result_of or
Boost.FunctionTypes metafunctions depending on whether the argument is a
pointer-to-member or not.

You could argue that the language should allow function-call syntax on
pointers-to-member-functions (and pointers-to-member-objects) as it is
allowed for ponters-to-functions, and...I might sympathize with you.

[snip errors]

HTH,

- Jeff



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net