Boost logo

Boost :

Subject: [boost] Checking for return type -- BOOST_STATIC_ASSERT?
From: Edward Grace (ej.grace_at_[hidden])
Date: 2009-08-20 18:41:34


I'd like to be able to make certain that a function/functor returns a
double precision floating point value.

I was always under the impression that it's essentially impossible to
check things based on return type. Is there a way to do this?
Something like BOOST_STATIC_ASSERT, who knows perhaps that *can* do it..

Ideally I would like to have some sort of compile type warning so
that in the following context,

class myclass {
public:
   ...
   template <class O>
   a_func(O functor) {
     ASSERT_IS_A_FUNCTOR(O);
     ASSERT_RETURN_TYPE_CONVERTABLE_TO_FLOAT(O);

   }
};

if O is compatible with the concept of a functor and O returns a type
that can be converted to a float, then we are good to go -- otherwise
I'd like an intelligible error.

If, for example, O is of the type 'void (*)()' I'd like it (the
compiler) to spit out,
   "The function pointer of type O must of signature float (*)()"

Any ideas?

-ed

------------------------------------------------
"No more boom and bust." -- Dr. J. G. Brown, 1997


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