Boost logo

Boost :

From: Corrado Zoccolo (czoccolo_at_[hidden])
Date: 2007-11-04 04:22:47


On 11/2/07, Mat Marcus <mat-lists_at_[hidden]> wrote:
>
> > My approach is different. You don't have to change the interfaces to use
> > optional_poly (so it is non intrusive with existing hierarchies), and
> you
> > don't need all this boilerplate code, but you have to use the ->
> operator to
> > access members of the class.
>
> [snip]
>
> You correctly note that the adobe::poly library requires more
> machinery to be provided by certain stakeholers. It does not,
> however, intrude into existing concrete classes.

[snip]

Ok, we are talking of two different things: intrusiveness w.r.t. existing
hierarchies vs. intrusiveness w.r.t. existing concrete classes.

Your example shows that adobe::poly<> is not intrusive w.r.t. existing
concrete classes, because it simulates concept maps with the boilerplate
code, but you are starting from a class that is not polymorphic (I would do
a similar think in those cases, look at my Callable example; the only
difference is that the boilerplate code seems to me more simple and natural,
because we create a hierarchy of classes, as we would usually do in OOP).

I'm concerned, though, of the case in which you already have a hierarchy of
polymorphic classes, and want to take advantage of value semantics, and
other possible optimizations e.g. small object.

If you look at my example on how to rewrite boost::any to have the small
object optimization using optional_poly, you will see how an existing
hierarchy:

        class placeholder
        {
        public: // structors

            virtual ~placeholder()
            {
            }

        public: // queries

            virtual const std::type_info & type() const = 0;

        };

        template<typename ValueType>
        class holder : public placeholder
        {
        public: // structors

            holder(const ValueType & value)
              : held(value)
            {
            }

        public: // queries

            virtual const std::type_info & type() const
            {
                return typeid(ValueType);
            }

        public: // representation

            ValueType held;

        };

is completely reused without changes (I only removed an unused method for
clarity of the example).
I think this is out of adobe::poly scope, or at least it is never covered in
the examples, so I cannot figure out how this would be done in practice.

Corrado

-- 
__________________________________________________________________________
dott. Corrado Zoccolo                          mailto:zoccolo_at_[hidden]
PhD - Department of Computer Science - University of Pisa, Italy
--------------------------------------------------------------------------

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