Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2003-01-30 14:27:39


--- Peter Dimov <pdimov_at_[hidden]> wrote:
> From: "Gennaro Prota" <gennaro_prota_at_[hidden]>
> > On Thu, 30 Jan 2003 10:19:53 -0500, David Abrahams
> > <dave_at_[hidden]> wrote:
> >
> > >Peter D. has effectively argued in the past that void *is* a supertype
> > >of everything (well, every object type, as opposed e.g. to
> > >function/function pointer types). Given the foregoing discussion
> > >about squares and rectangles it may be the *only* supertype that we
> > >can detect with certainty.
> >
> > And since Peter D. is not in the habit of making trivial errors, this
> > makes me wonder in fact what definition of "supertype" he was
> > considering.
>
> The practical one. I.e. if you use is_base_and_derived<B, D> somewhere, do
> you want "true" for B=void, if B can be void?

Ah, ok. So you've not argued that void is a supertype, just that you want the
template, conventionally, to yield void in such a case. Then you can always add
a level of indirection:

template <typename B, typename D>
struct is_base_and_derived {
   /* "normal meaning" implementation */
};

template <typename B, typename D>
struct extended_is_base_and_derived {
  static const bool value = is_base_and_derived<B, D>::value;
};

template <typename D>
struct extended_is_base_and_derived<void, D> {
 static const bool value = true;
};

> For example, if you write a class template X<T> that is supposed to only
> operate on types derived from T (e.g. an inheritance-bounded variant), how
> would you denote the unbounded case?
>
> A related question would be: if you had common_base<X, Y>::type, what would
> you want returned when X and Y have no common base?

Yes, that's a little trickier. Basically, if you choose to yield an error when
X and Y have no common base than you can't simply wrap it as above. However if
you, for instance, encapsulate the have_common_base<> logic then it's easy.

Genny.

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com


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