[concept check][mpl] (Conditional) Concept checking for functions
One rough idea I had was that since I will always have boost::function declarations as the default type, I could try to see if the type F is compatible with the boost::function type? Could this be done in a simple metafunction similar to the following: template<class BoostF, class F> struct CheckFunctionCompatible { static void Check() { F f; BoostF fboost = f; //If this fails, then I am basically failing } }; But then if I instantiate, won't it also try to instantiate the constructor? template<class F> class { typedef CheckFunctionCompatible<boost::function<double (double)>, F> test_F_compatibility; }; Of course, this wouldn't work for detecting the signature of the function, but that is a 2nd order feature for me. Of course, this also assumes that F can be constructed with no parameters, but this also might be reasonable for me if there is no better solution. -Jesse
AMDG Jesse Perla wrote:
One rough idea I had was that since I will always have boost::function declarations as the default type, I could try to see if the type F is compatible with the boost::function type? Could this be done in a simple metafunction similar to the following:
template<class BoostF, class F> struct CheckFunctionCompatible { static void Check() { F f; BoostF fboost = f; //If this fails, then I am basically failing } };
But then if I instantiate, won't it also try to instantiate the constructor?
You could do it like this, but I doubt the error messages from deep inside boost::function will be very helpful. template<class BoostF, class F> class CheckFunctionCompatible { public: BOOST_CONCEPT_USAGE(CheckFunctionCompatible) { BoostF test(f); } private: F f; }; In Christ, Steven Watanabe
On Mon, Mar 30, 2009 at 10:41 PM, Steven Watanabe <watanabesj@gmail.com>wrote:
You could do it like this, but I doubt the error messages from deep inside boost::function will be very helpful.
template<class BoostF, class F> class CheckFunctionCompatible { public: BOOST_CONCEPT_USAGE(CheckFunctionCompatible) { BoostF test(f); } private: F f; };
In Christ, Steven Watanabe
Steven, Thanks as always. Is there any way to turn this into a metafunction predicate? I don't mind hardcoding a specific boost::function predicate for each function I am testing, which might be a better idea anyways for clarity. Thanks, Jesse
participants (2)
-
Jesse Perla
-
Steven Watanabe