Re: [Boost-bugs] [Boost C++ Libraries] #2563: [boost][serialization] void_upcast is very slow

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #2563: [boost][serialization] void_upcast is very slow
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-12-12 08:41:06


#2563: [boost][serialization] void_upcast is very slow
----------------------------------+-----------------------------------------
  Reporter: jacobholm_at_[hidden] | Owner: ramey
      Type: Feature Requests | Status: closed
 Milestone: Boost 1.38.0 | Component: serialization
   Version: Boost 1.37.0 | Severity: Optimization
Resolution: invalid | Keywords:
----------------------------------+-----------------------------------------

Comment(by jacobholm_at_[hidden]):

 {{{
 /inline void *
 void_upcast(
  extended_type_info const & derived,
  extended_type_info const & base,
  void * const t
 ){
   return const_cast<void*>(t);
 }/
 }}}

 The code above was the first to be suggested. This code will not work with
 multiple inheritance. Then there would be need for a method that detects
 if there is multiple inheritance or not. But if we were to modify it to
 use templates and static_cast it would work with multiple inheritance as
 well:

 {{{
 template <typename A>
 class cast
 {
 public:

  template<typename B>
  static A* void_upcast(
    B* const t
  )
  {
    return static_cast<A*>(const_cast<B*>(t));
  }
 };
 }}}

 Example using the above code:

 {{{
 const B *t;

 cast<A*>::void_upcast(t);
 }}}

 This solution is based on that we know the class type so that we can call
 the template class.

 I also have some comments your conclusions:

 c) Why will the serialization fail with static_cast? Perhaps you could
 provide a code example?

 d) It is meant to show that static_cast may change the pointer when
 casting with multiple inheritance, and never change the pointer when using
 single inheritance.

 Yours sincerely,

 Jacob Holm

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/2563#comment:4>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:59 UTC