Boost logo

Boost :

From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2003-01-31 08:56:17


Rani Sharoni wrote:
>
> Here is a weird (but working !) version:
>
> template <typename B, typename D>
> struct helper
> {
> template <typename T>
> static yes check(int B::*, T);
> static no check(int D::*, int);
> };
>
> // TODO: add cv-qualifiers to B and D
>
> template<typename B, typename D>
> struct is_base_and_derived
> {
> struct Host
> {
> operator int D::*() const;
> operator int B::*();
> };
>
> enum { result =
> sizeof(helper<B,D>::check(Host(), 0)) == sizeof(yes)
> };
> };
>
> BTW: the relevant section in the C++ standard is 13.3.3.2/4/3 (especially
> the foot note).

Cool. I modified it a bit, my version works for the GCC 3.2.1 and the
Intel 7 - with no namespace polution from 'helper':

template< typename B, typename D >
struct is_base_and_derived
{
private:
   struct detail
   {
      template< typename T >
      static yes check( int B::*, T );
      static no check( int D::*, int );

      struct host
      {
         operator int D::*() const;
         operator int B::*();
      };
   };

public:
   enum {
      value = sizeof detail::check( detail::host(), 0 ) == sizeof( yes )
   };
};

Regards, Daniel

-- 
Daniel Frey
aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de

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