I am interested in tag dispatching in a generic function depending on
whether the passed in argument is arity 1 or 2.
My problem is that I want to have a generic expectation operator that
is passed in a function to take the expectation over, and a
distribution for the integration. The expectation needs to support
both real and mixed-integer measures and functions. Consider the
following functions it should work with:
struct my_real_functor
{
template
double operator()(ublas::bounded_vector& x) {...}
};
template
double my_real_function(ublas::bounded_vector& x) {...}
struct my_mixed_functor
{
template
double operator()(ublas::bounded_vector& real_x,
ublas::bounded_vector& int_x) {...}
};
.... naturally, part of the problem is that the functor could have
both specializations,
so I recognize this might be tricky. If both are on a functor, then I
can default to
one of the implementations(probably the unary) for the matching.
---------------------------------------------------
For the operator itself, the signature would be something like.
double expectation(F f, const Distribution& dist)
{
.....// tag dispatch depending on F arity, or something similar.
}
..... or even better:
double expectation(mpl::enable_if::type f, const
Distribution& dist)
{
.....//unary implementation
}
double expectation(mpl::enable_if::type f, const
Distribution& dist)
{
.....// binary implementation.
}
.... or even better if I could fully match the signatures of the
passed in F for conformance.
------------------------------------------------------
I looked at boost function_traits but it doesn't work with member
functors....
http://www.boost.org/doc/libs/1_39_0/libs/type_traits/doc/html/boost_typetra...
Any ideas on how best to implement this?
Thanks as always,
Jesse