Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-03-11 16:49:18


Douglas Gregor wrote:
> On Thursday 11 March 2004 10:35 am, Peter Dimov wrote:
>> void f();
>> my_function<void()> g(f);
>> your_function<void()> h(g);
>>
>> g == h; //???
>
> I'd bet that this results in a compilation error, so the user would
> know to try on of these syntaxes:
>
>> g.contains(h); // false
>> h.contains(g); // true

For some reason, I think that you are busy and don't have much time to read
your e-mail. :-)

The problem here is that you are establishing an idiom that represents
'contains' via the following signatures:

    template<...> bool operator==(function<...> const & f, G g);
    template<...> bool operator==(G g, function<...> const & f);

My point is that this idiom is not applicable to other function<>-like
classes, because if you also have

    template<...> bool operator==(my_function<...> const & f, G g);
    template<...> bool operator==(G g, my_function<...> const & f);

you can neither ask a function<> whether it contains a my_function<>, nor
can you ask a my_function<> whether it contains a function<>, as both
classes claim the mixed operator== for _their_ 'contains' operation.

> I'd bet that this results in a compilation error, so the user would
> know to try on of these syntaxes:
>
>> g.contains(h); // false
>> h.contains(g); // true

Good luck, if the authors haven't provided 'contains' as a member.

>> It's limited to the one and only function<> (and you can't even ask a
>> function<> whether it contains another function<>, right?)
>
> Right, you can't compare function<> objects, but you can compare a
> function<> object to something it could target.

A function<> can target another function<>, can it not?


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