I have a variety of user defined function objects that I will need to call.
Take the following examples:template
struct Func1{ double operator()(boost::array&
x1, boost::array& x2){...}};
template<int N1>
struct Func2{ double operator()(boost::array& x){...}};
With a function such as
template&
x1, boost::array& x2)>
class DPP{ void solve(){...... uses F...to be discussed} };
I have a few questions:
1) Is there a relatively easy way to use boost concept check to verify that
F follows the first function signature so that I can detect compile time the
problem? I can't figure out how to do it from the concept check docs, and
they say they are out of date.
Usage I want to check in the instantiation of DPP:
F f;
f(boost::array& x1, boost::array& x2)
2) I want the user to be able to pass in a simplified function type if N2 =
0
I assume that to call the actual function I would have some kind of impl
function with partial specialization such as:
template
struct use_f_impl();
template
struct use_f_impl{
static double use_f()
{
STATIC_ASSERT(N2 == 0);
F f;
boost::array x;
return f(x);
}
};
template
struct use_f_impl{
static double use_f()
{
F f;
boost::array x1;
boost::array x2;
return f(x1, x2);
}
};
And then in my solve() function I go:
double val = use_f<(N2 == 0, N1, N2)>::use_f();
Is this the right idiom, pattern, etc? Do I need to use the struct with a
static function since function templates don't have partial specialization?
3) Now what if I want to do a concept check on the F passed into DPP? It
has to be conditional on the N2 value now. How would I do this?
4) Lets say that I don't want to force them to use the simplified version of
the function signature if they don't want to.
Can I automatically detect the signature and put it into a flag integer in
the class?
i.e. inside of the DPP class:
static bool use_simple = IsSimple<F>::value;
Then pass in the use_simple value when calling use_f_impl.
If so, what would the IsSimple metafunction look like and can concept check
help?
Thanks,
Jesse