|
Boost Users : |
Subject: [Boost-users] [traits/function_types/generic] Can F be called with {a0, ..., aN}?
From: Rutger ter Borg (rutger_at_[hidden])
Date: 2010-03-02 15:06:58
Hello,
I have been trying to achieve assignment to a variant of functions,
typedef boost::variant<
boost::function< int >,
boost::function< int, int >
> variant_type;
which is nice until you try to assign an ambiguous callable object to it,
especially if the callable object has templates or similar.
This has lead to my question: is there a way to know (without the "no
matching function call" compiler error if {a0,...,aN} in F(a0,a1,...,aN) are
permissible arguments to callable object/function F?
I thought I had a nice solution by overriding boost::result_of<
F(a0,a1..,aN)>::type in such way that it doesn't give compile errors if a
type doesn't exist, but mpl::na (in conjunction with a has_result_of<T>
meta-function).
Then, writing functors like
struct some_func {
template< typename Sig >
struct result {
// no type defined here, so result_of<>::type is not defined
}
template< ... >
struct result< enable_if arguments are acceptable > {
typedef ... type;
}
R operator()( ... ) {}
};
gives you the ability to answer the question for those particular functors.
However, some widely used stuff like boost::bind always has a result_type,
so this trick was a dead end.
So, in short, does anyone know of a generic trick to know if F can be called
with a set parameters {a0,...,aN} (without the compile error)?
Thanks,
Cheers,
Rutger
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net