Boost logo

Boost :

From: David Bergman (davidb_at_[hidden])
Date: 2006-07-24 09:43:31


I have a new version of my counter-proposal (or suggestion, I just want to
take FULL advantage of the power in his idea...) to Beman's 'identifier'
notion. My proposal was a more generic 'embed_type' with various policies.
The old version (a few hours old now...) used a set of fixed flags in order
to enable or disable certain homomorphisms. The new version handles that
much better, via a vector of policy types.

I also have a (somewhat associated) proposal - that I just created - to
create a hierarchy from a vector of types. Actually, two different kinds of
hierarchies:

1. A spine-like hierarchy, where the types are attached as maximal elements.

        struct A { void a() {} };
        struct B { void b() {} };
        struct AB : generate_spine<mpl::vector<A, B> > {};
        AB ab; ab.a(); ab.b();

2. A chain, where the types have "holes"

        template<class Base>
        struct A : Base { void a() { b(); };
        struct B : Base { void b() {};
        struct AB : generate_chain<mpl::vector<quote_raw3<A>, quote_raw3<B>
> {};

I have gathered those two proposals in files 'embed_type.hpp' and
'generate_hierarchy.hpp', which I will upload as soon as I get access to the
vault. Till then, I talk about the hierarchy generation here:
http://davber.blogspot.com/2006/07/hierarchy-generation-in-c.html.

Back to the 'embed_type' proposal, an example - which happens to be Beman's
'identifier' looks like:

        template <typename T, typename D>
        struct identifier : embed_type<T, D,
mpl::vector<policy<embed_order>, policy<embed_equivalence> > > {};

A more concrete example (yes, I know it will fail on GCC 3.4, due to the
base class being mentioned in the constructor without the type parameters;
ugh...):

        class CustomerId : public embed_type<int, CustomerId,
                mpl::remove<embed_policies_isomorphism,
policy<embed_conversion> >::type>
        {
                CustomerId(int num) : embed_type(num) {}
        }

        CustomerId id = 42;
        int idNum = id; // Will fail, since we removed the conversion
policy!

In this case we preserved all operations minus conversion to int, which we
explicitly removed from the type vector.

/David


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk