|
Boost Users : |
Subject: Re: [Boost-users] Auto dispatch metaprogramming tricks
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-05-21 11:20:46
AMDG
Kim Kuen Tang wrote:
> as indicated by strasser i have also difficulties to compile your
> code. But your code seems to be more generic, since you dont need to
> provide the result_type of the member function.
>
> Can you provide a working example?
A couple bugs:
* CV qualifiers we're causing an ambiguity.
* I missed a pair of parentheses.
* At least one overload of on is required.
The following compiles for me:
#include <boost/mpl/bool.hpp>
#include <boost/mpl/assert.hpp>
typedef char no;
struct yes { char dummy[2]; };
struct has_on_result {
has_on_result operator,(int);
};
no check_on_result(const has_on_result&);
yes check_on_result(...);
template<class T>
struct has_on_impl : T {
using T::on;
has_on_result on(...) const;
};
template<class T, class M>
struct has_on : boost::mpl::bool_<
sizeof(check_on_result((((has_on_impl<T>*)0)->on(*((M*)0)), 0))) !=
sizeof(no)
> {};
struct has_on_struct {
int on(int) const
{
return 1;
}
};
struct arbitrary_struct {
int on(void*) const
{
return 1;
}
};
int main() {
BOOST_MPL_ASSERT((has_on<has_on_struct,int>));
BOOST_MPL_ASSERT_NOT((has_on<arbitrary_struct,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