[C++-sig] Boost.Python code generator
Nicodemus
nicodemus at globalite.com.br
Fri Dec 6 15:35:14 CET 2002
David Abrahams wrote:
>I gave this some thought last night.
>
>We could have the following expressions define __getitem__ and
>__setitem__, respectively:
>
> .def(self[unsigned()])
> .def(self[unsigned()] = float())
>
>
>If the class defines a "size()" member function we could use that to
>define a __len__ function and to throw an IndexError.
>
>If the class defines a nested key_type type and find() and end()
>member functions we could use x.find(key) != x.end() to throw KeyError
>
>Otherwise, the class' __len__ function (if any) could be used to throw
>an IndexError, if to the arguments to operator[] are unsigned integral
>types.
>
>All this can be done without a code-generating front-end, at least on
>conforming compilers. I think that in fact most of it is portable to
>all supported platforms.
>
Very nice!
The only problem I see is classes that don't follow standard names (Size
instead of size, for instance), but even then a thin wrapper class could
be used without problems, right?
struct MyVecWrap: public MyVec
{
unsigned int size() const
{
return Size();
}
};
struct MyIntDict: public IntDict
{
typedef int key_type;
int* find( int );
int* end() { return 0; }
};
>
More information about the Cplusplus-sig
mailing list