Boost logo

Boost :

From: Beman Dawes (beman_at_[hidden])
Date: 1999-09-01 07:40:34


Looking at 7.3.1.1 [namespace.unnamed], it seems the following
technique allows the use of assert() in a header without introducing
an ODR violation.

namespace boost {
  namespace {
    template <class Derived, class Base>
    inline Derived polymorphic_cast(Base* x) {
        assert( dynamic_cast<Derived>(x) != 0 ); // detect logic
error
        return static_cast<Derived>(x);
    }
  }
}

If this doesn't work, please break it to me gently. I already have a
headache from thinking about assertions and the ODR.

It also does nothing to address Kevlin's other concerns regarding use
of assert in the cast functions. But that is a somewhat different
discussion.

--Beman


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