|
Boost Users : |
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-07-16 18:42:16
AMDG
Michiel Helvensteijn wrote:
> Ok, the subject-line might be a bit confusing. :-)
>
> I have the following template function:
>
> template<class T>
> bool is(const string& str);
>
> Its implementation is not important. It checks if a string can be converted
> to type T by std::stringstream. I also have the following function:
>
> template <class T>
> function<bool (T)> neg(function<bool (T)> func) {
> return !bind(func, _1);
> }
>
> Which I use in the following way:
>
> BOOST_CHECK_PREDICATE( neg(is<int>), ("text") );
>
> But the compiler (GCC 4.1.2) complains:
>
> error: no matching function for call to 'neg(<unresolved overloaded function
> type>)'
>
> What's the problem. And, also, what's the solution? :-)
>
Internal to the compiler, the type of is<int> is a special type used to
flag overloads. (unresolved overloaded function type). The problem is
that you are passing this special type to a function template (the
boost::function constructor) which does not provide enough information
to resolve the overloading. The solution is to add a cast:
static_cast<bool(*)(const std::string&)(&is<int>)>
In Christ,
Steven Watanabe
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