Boost logo

Boost :

From: Kevlin Henney (kevlin_at_[hidden])
Date: 2001-02-14 07:38:50


In message <3A8A5454.2F60A3CB_at_[hidden]>, Daniel Frey
<daniel.frey_at_[hidden]> writes
>I wonder if the following problem is common enough to make it to the
>utility.hpp-header :)

Although a good case can be made for it be a static assertion, in the
sense of the <boost/static_assert> library.

>template< class Parent, class Child > class parent_of
>{
>public:
> parent_of() {
> if( false ) { // Allow easier optimization
> Child* p; Parent* q = p;
> }
> }
>};
>
>this allows me to use:
>
>template< class T > class pointer : parent_of< Object, T >
>
>to express (and document!) that I expect the class T to be derived from
>Object.

This would be better expressed in terms of non-inherited constraints --
the empty base class optimisation does not work on all platforms, and
you don't really want your constraint to impose on the parentage of the
class you are defining.

I wrote something like this a few years ago, and IIRC one thing you have
missed is a check that Parent is not void. A simple sizeof(Parent) will
do the trick.

In terms of terminology, perhaps is_derived, or something along those
lines would be better. Similarly, Base and Derived rather than Parent
and Child.

Kevlin
____________________________________________________________

  Kevlin Henney phone: +44 117 942 2990
  Curbralan Limited mobile: +44 7801 073 508
  mailto:kevlin_at_[hidden] fax: +44 870 052 2289
  http://www.curbralan.com
____________________________________________________________


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