|
Boost : |
From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2002-07-30 16:10:38
> > [...]
> > ptr<Derived> pD = new Derived;
> > ptr<Derived, X> pX = new X;
> > ptr<Derived, Y> pY = new Y;
> >
> > pX = pD; // Won't work
> > pY = pD; // Won't work
> > [...]
>
> Of course, this syntax is clumsier than existing pointers, and also less
> powerful. For instance, you may have code that knows about X or Y,
> but not about anything derived from X or Y. Your proposal requires
> such code to know about all possible derivatives in order to work
> properly, which is a fairly restrictive requirement.
Well we could restrict assignments from whom offsets differ only. Here is a
clumsy compile-time assertion example (I'm sure someone else can build one
more cleanly):
template <void *, void *>
struct validate_equality;
template <void * _P>
struct validate_equality<_P, _P>
{
static bool const result = true;
};
Y aY = * reinterpret_cast<Derived *>(0);
Derived aD = * reinterpret_cast<Derived *>(0);
{
validate_equality<(void *) & aD, (void *) & aD>::result;
}
Philippe A. Bouchard
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk