python::object && mpl

David Abrahams david.abrahams at rcn.com
Fri Jan 11 17:44:09 CET 2002


> I see.
> If our generators have 2 parameters we could use binary_function:
>
> template <class Object>
> struct use_generator
> {
>     template <class Generator, class Base>
>     struct apply
>     {
>         typedef mpl::binary_function<Generator,Object,Base>::type type;
>     };
> };

Sorry, I'm not familiar with binary_function and I don't know what it does.

> <<<
>    Another possibility would be to make all capabilities into templates,
so
>
>    template <class
>
>    >>>
>
> Something missing?

Uh, yeah, sorry. The capability generator would be

enum checking_t { unchecked, checked };
template <checking_t checking = unchecked>
struct indexable
{
    template <...>
    struct apply
    {
        ...
    };
};

Now you can write indexable<> most of the time, and if you want checking,
indexable<checked>

> Sounds good!
> How about has_capabilities on a type_list of capabilities and using
> mpl::for_each to validate all?

Fine, but probably fancier than the average user needs. It would be perfect
for your meta-object's constructor/assignment from PyObject*/ref, though.

> x.has_capabilities<type_list<indexable,...> >() /
> x.has_capabilities<integral_capabilites>() / ...
> (integral_capabilities = mpl::type_list<addable,...>)

Very nice. Looks like you're getting the hang of this metaprogramming stuff!

-Dave





More information about the Cplusplus-sig mailing list