[C++-sig] enums and structs

David Abrahams david.abrahams at rcn.com
Mon May 20 04:08:57 CEST 2002


----- Original Message -----
From: "joel de guzman" <djowel at gmx.co.uk>
To: "David Abrahams" <david.abrahams at rcn.com>; <c++-sig at python.org>
Sent: Sunday, May 19, 2002 8:16 PM
Subject: Re: [C++-sig] enums and structs


> Hi Dave,
>
> You don't have to CC me here, I subscribed to the list.
>
> ----- Original Message -----
> From: "David Abrahams" :
>
> > Since Joel is doing some work with enums now, it might make sense for
him
> > to implement this. What do you think, Joel?
>
> Ok. I will. I was in fact thinking of a variation of the
> syntax that you posted before. What do you think
> about:
>
> enum MyEnum { one = 1, two, three };
>
> my_module.add(
>
>     enum_<MyEnum>("MyEnum")
>     [
>         enum_val("one", one),
>         enum_val("two", two),
>         enum_val("three", three)
>     ]
> );
>
> Kinda like Phoenix-ish. Tell me if it's too cute for your taste ;^/

I like the Phoenix-isms, and I even think it might make sense to re-do the
entire interface that way at some point:

module("my_module")
[
    def("x", x),
    def("y", y),
    ...

    class_<MyClass>("MyClass")
    [
        def("foo", &MyClass::foo),
        def("bar", &MyClass::bar),
        ...
    ],

    enum_<MyEnum>("MyEnum") [ ... ]
]

Whatever happens, classes, enums, and modules should probably all use a
consistent interface...
However, the above approach would complicate things quite a bit, since the
wrapped class type needs to interact with the member pointer type (see the
member_function_cast ugliness in the implementation). We'd need to switch
to a delayed evaluation scheme for the def() functions, and I don't think
it's time to do that right now.

Also, the interface direction from my email was supposed to produce a
different result than enums-as-ints... though I guess there's no reason we
couldn't start with as-int conversion and switch to int subclasses later,
using the same interface.

> Implementation wise, I'm still trying to grok the innards of
> BPL. I'm not even close yet, but I'll be- surely ;-)

I hope you've been watching the CVS documentation as it gets updated.
Things are getting better...

-Dave







More information about the Cplusplus-sig mailing list