|
Boost Users : |
From: Michael Marcin (mike_at_[hidden])
Date: 2007-03-21 04:43:31
Gennadiy Rozental wrote:
> "Michael Marcin" <mike_at_[hidden]> wrote in message
> news:etqf0t$6ea$1_at_sea.gmane.org...
>> Unless I'm missing something it looks like polymorphic_downcast doesn't
>> provide an overload for reference types... is there a reason? This
>> makes it a little inconvenient for use.
>
> I brought this up some time ago. No one seemed to care enough to work on
> docs update. As usual in many volunteering based projects ;)
>
> R u up to it?
>
Is the problem the docs or the lack of an overload supporting
references? Shouldn't something like this work?
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/add_pointer.hpp>
#include <boost/utility/addressof.hpp>
namespace boost
{
template <class Target, class Source>
inline Target polymorphic_downcast( Source& x )
{
BOOST_ASSERT( dynamic_cast< typename add_pointer< typename
remove_reference<Target>::type >::type >( addressof(x) ) == addressof(x)
); // detect logic error
return static_cast<Target>(x);
}
} //end namespace boost
Thanks,
Michael Marcin
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net