python::object && mpl
David Abrahams
david.abrahams at rcn.com
Fri Jan 11 16:50:52 CET 2002
----- Original Message -----
From: "Arnaldur Gylfason" <arnaldur at decode.is>
>
> Dave,
>
> I've glanced through mpl and have a rough idea about it's function.
> From what I gather, the use_generator
Sorry, I've lost track of what use_generator is. Is that something I wrote
in my little prototype? Oh, I see below.
> is the Glue function class and the
> generators have to support templated inheritance but don't need to be
> function classes.
By templated inheritance I assume you mean inheritance from a template
argument?
> The following design should be possible:
>
> template <class T, bool checked, class Base>
> indexable : Base
> {
> proxy operator[](...
> ...
> };
>
> ...
>
> template <class...., checked>
> struct object
> : gen_linear_hierarchy<
> typename get_unique_generators<mpl::type_list<c1,c2...cn> >::type
> , use_generator<
> object<c1,c2,c3...cn>, checked>
> >
> >
> {
> };
> ...
>
> template <class Object,checked>
> 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 argument.
> };
> };
It looks like this design doesn't allow selecting individual capabilities
for checking. I think it should be possible to specify that sequence
minimally checks for indexable, but may have other capabilities, like
sliceable, in its interface.
> Is my understanding correct?
> What design would you opt for?
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.
Another possibility would be to make all capabilities into templates, so
template <class
BTW, if we are going to allow some features to be present in the interface
but unchecked there should be an interface for checking for support of those
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 don't
make the generalized (metaprogram) object template now.
-Dave
More information about the Cplusplus-sig
mailing list