python::object && mpl

Arnaldur Gylfason arnaldur at
Fri Jan 11 17:23:51 CET 2002

   > struct use_generator
   > {
   >     template <class Generator, class Base>
   >     struct apply
   >     {
   >         typedef Generator<Object,checked,Base> type;
   this requires Generator to be a template template argument, not
   supported by
   all compilers. That's one reason to use the MPL metafunction approach:

   struct indexable
       tempalate class<T,...>
       struct apply
           typedef indexable_t<T,...> type;
           // where indexable_t is your "indexable", renamed

   Now you can pass indexable_generator as a regular template type

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;

It would also apply to other usage of our generators as metaclass
There is this checked thing though.

   One possibility might be:

   template <class CapabiltiesList, class CheckedList>
   struct object
       : ...

   You'd want to STATIC_ASSERT that all elements of CheckedList were in
   CapabilitiesList. Capabilities in CheckedList would also be checked.

That's one way to do it. Have to think about this more thoroughly before I
form an opinion about the best approach.

   Another possibility would be to make all capabilities into templates, so

   template <class


Something missing?

   BTW, if we are going to allow some features to be present in the
   but unchecked there should be an interface for checking for support of
   features without throwing an exception:

       void f(sequence x)
           if (x.has_capability<sliceable>()) {...}

   This could be a reason to make the metafunctions available even if you
   make the generalized (metaprogram) object template now.


Sounds good!
How about has_capabilities on a type_list of capabilities and using
mpl::for_each to validate all?
x.has_capabilities<type_list<indexable,...> >() /
x.has_capabilities<integral_capabilites>() / ...
(integral_capabilities = mpl::type_list<addable,...>)



More information about the Cplusplus-sig mailing list