Boost logo

Boost Users :

Subject: Re: [Boost-users] Auto dispatch metaprogramming tricks
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-05-21 11:10:24


AMDG

strasser_at_[hidden] wrote:
> Zitat von Steven Watanabe <watanabesj_at_[hidden]>:
>> Yes. The code looks something like this:
>>
>> 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(...);
>> };
>>
>> 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)
>>> {};
>
> how does this work with member functions that have a "void" result?
> does it?

It handles void. That's what the comma operator is for.

> how does this work at all? "using T::on" is invalid when T doesn't
> have "on", so the instantiation of has_on<>, that should result in
> mpl::false_, fails.

Requiring at least one overload of on, is not
particularly onerous in this context. If you're
willing to require the exact signature, you can
use SFINAE as in Kim's post.

> do you have a link to actual code that uses this?

I think proto uses something like this for operator().
There are a few extra tricks that work for this however.

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