Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2005-07-02 15:00:43


Daniel James wrote:
> Joel de Guzman wrote:
>
>> struct some_baz
>> {
>> int impl(foo, int x) { return x + 1; }
>> int impl(bar, char const* s) { return std::strlen(s); }
>> };
>
> With Jonathan's library this would be:
>
> struct some_baz
> {
> int foo(int x) { return x + 1; }
> int bar(char const* s) { return std::strlen(s); }
> };
>
> A major advantage in my opinion. I think it also supports overloads.

Oooh, I didn't notice that. For me, that's a killer. I definitely want
interfaces to be compatible with existing classes, such as containers and
iterators. I'm even hoping to allow interfaces to declare non-member functions
and allow instances to bind to non-class types.

I still haven't had time to think about Joel's proposal. However, I did spend
consider effort at one point trying to support simple handwritten interfaces
using ordinary member function syntax, and convinced myself that it was probably
not possible. This might be because I had stronger requirements than Joel,
though. Among other things, I required:

1. support for derived interfaces, including MI
2. interface instance, including those involving MI, should have the size of a
struct conatining two pointers (assuming the degree of EBO currently provided by
most compilers)
3. It should be possible to define a const view const_view<IBar> of an
interface, in which non-const functions are disabled. (Ordinary
const-qualification is insufficient, since you can make a non-const copy of a
const interface instance)
4. Implicit derived-to-base and non-const-to-const conversions
5. Support for aspect oriented programming.

For 2 and 5 -- at least -- I concluded that interfaces need to contain a nested
rebind-like structure which allows them to be reinstantiated with different base
classes. Since it's redundant to implement an interface's infrastructure twice,
I put the rebind stuff in a helper class, and made the actual interface derive
from an appropriate specialization of rebind. I was unable to find any way for
users to write this stuff by hand without going insane.

The template-based IDL looks like it is potentially the most usable. The only
open question is whether compile-times will suffer unduly.

Jonathan


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