Boost logo

Boost :

Subject: Re: [boost] Checking for return types (result_of) - redux..
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-08-21 11:04:39


Edward Grace wrote:
> On 21 Aug 2009, at 15:29, Steven Watanabe wrote:
>
> It seems quite unedifying having to make sure the user adds some,
> apparently arbitrary, magic typedef to their functors in order to
> make sure it works.
>
> My original motivation was to form a helpful compile time assert for
> the user, which I thought would be good practise. It appears all this
> does is to shift a conceptually straightforward problem (make sure
> your functor/function returns something) to an even more obscure one
> "ordinary functions are fine but make sure you define a return_type
> typedef in your functions oh.. and make sure the return type of the
> operator()() is the same as that... " Then I have to add a way of
> sanely catching if they have not done this - I doubt I can... Crazy!

Why not define your code to take a boost::function<double(/* whatever goes here */)>?

Is the argument list variable? If so, aren't you already aware of that variance to use in the function type argument for boost::function?

If that doesn't work, you'll need all of the crazy stuff that template argument packs will solve conveniently to accept N arguments:

   template <class R>
   R
   foo(boost::function<R()>);

   template <class R, class Arg1>
   R
   foo(boost::function<R(Arg1)>);

   template <class R, class Arg1, class Arg2>
   R
   foo(boost::function<R(Arg1, Arg2)>);

etc.

HTH,

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk