Boost logo

Boost :

Subject: Re: [boost] RFC: type erasure
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-05-24 19:58:20


AMDG

On 05/24/2011 04:39 PM, Giovanni Piero Deretta wrote:
> On Mon, May 23, 2011 at 11:01 PM, Steven Watanabe <watanabesj_at_[hidden]> wrote:
>> struct callable1 {
>> int operator()(int);
>> };
>>
>> struct callable2 : callable1 {
>> double operator()(double);
>> };
>>
>
> This can be solved by an "using callable1::operator();" . I just had
> to solve a very similar problem 20 minutes ago, but in my case all the
> elements in the inheritance chains only had operator() in need of
> un-hiding.
>
> I guess the problem in your case is that in general your callable2 is
> not necessarily inheriting from something that is callable, that is,
> you are using operator() as the name but it could be anything.

Exactly.

> A
> solution is adding every possible name (but with special arguments so
> that they won't actually partecipate in overload resolution) in the
> most base class and adding an "using <every possible name> at every
> level of the inheritance:
>

I've used this solution in the past. Now, I think
it's better to detect the second and subsequent
instances and add a using declaration. The advantage
is that there are no extra overloads, so &any<...>::operator()
is unambiguous if there's only a single overload.

> Probably it will break in some cases I'm not foreseeing. Will
> definitely not work for user specified foo-able.
>

In Christ,
Steven Watanabe




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk