Boost logo

Boost :

Subject: Re: [boost] [type_erasure] Review started (July 18-27, 2012)
From: Christophe Henry (christophe.j.henry_at_[hidden])
Date: 2012-07-24 13:39:26


> 2. Is it possible to convert between "any" instances with different
> concept
> sets or value types? For instance, are these possible?
> any< mpl::vector<
> addable<>,
> incrementable<>,
> decrementable<> >
> > a;
>
> any< mpl::vector<
> addable<> >
> > b = a;

I find this an interesting question. I use the review to change a private
but real project and replace all of my OO-style interfaces by TypeErasure. I
got the following to compile and work (you need copy_constructible):

typedef any< boost::mpl::vector<
          boost::type_erasure::typeid_<>,
          boost::type_erasure::copy_constructible<>,
          boost::type_erasure::addable<>,
          boost::type_erasure::incrementable<>,
          boost::type_erasure::decrementable<> >
> AnyA;

        typedef any< boost::mpl::vector<
          boost::type_erasure::copy_constructible<>,
          boost::type_erasure::typeid_<>,
          boost::type_erasure::addable<>
>
> AnyB;

          AnyA a(10);
         AnyB b = a;

OTOH, this does not compile:
       AnyB b2(10);
      AnyA a2=b2;

Which brings me to the following use case. Supposing I have 3 classes IA <-
IB <- IC and 1 object of each held as shared_ptr, I can dynamic_pointer_cast
from one to another. But if I have 3 any's of concepts A,B,C, B containing
A's concepts + some more, and C containing B's concepts + some more, I can
"upcast" as shown above from C to B and B to A, but not the other way
around, right? Even if I have an object fulfilling A,B and C.

Thanks,
Christophe

PS: so far I got only one warning: check_match does not use its parameter
op.


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