
Edward Grace wrote:
If all you are doing is checking the return type, you are probly better off using Boost.ConceptCheck.
That does, conceptually, (pardon the pun) seem like a good idea.
While my above kludge will work, along with the use of boost::function I'd rather get what I want -- a guarantee of the return type being correct or a compile error, than effect that outcome through some other means.
I'm not (at all) familiar with it's usage of Boost.ConceptCheck, something like this perhaps?
template <class O> BOOST_CONCEPT_REQUIRES( ((Generator)), (double) ) void class_scope<types...>::measure_execution_time(O f,.... etc...) { code goes here... }
Here O is the abstract function object, it could be a member function ordinary function, anything that can be invoked with
f();
Since it takes no arguments it's presumably a model of 'Generator' and I require it's return type to be 'double'.
Before I get knee deep in compiler errors, does that seem about right to you?
Cheers for this,
-ed
http://www.boost.org/doc/libs/1_39_0/libs/concept_check/reference.htm#functi... I use BOOST_CONCEPT_ASSERT in my own code: template< ... > template< class O > void class_scope< ... >::measure_execution_time(O f, ...) { // Assert that, e.g., // double x = f(); // is okay. BOOST_CONCEPT_ASSERT((boost::Generator< O, double >)); ... } I expect the following (or something like it) is what you'd do if you prefer BOOST_CONCEPT_REQUIRES, but as alluded to above, I've never actually used BOOST_CONCEPT_REQUIRES. template< ... > template< class O > BOOST_CONCEPT_REQUIRES( ((boost::Generator< O, double >)), void ) class_scope< ... > ::measure_execution_time(O f, ...) { ... } - Jeff