Re: [Boost-bugs] [Boost C++ Libraries] #2862: slist::swap is broken when cache_last< true > is used

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #2862: slist::swap is broken when cache_last< true > is used
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-03-17 08:06:35


#2862: slist::swap is broken when cache_last< true > is used
---------------------------+------------------------------------------------
  Reporter: andysem | Owner: igaztanaga
      Type: Bugs | Status: new
 Milestone: Boost 1.39.0 | Component: intrusive
   Version: Boost 1.38.0 | Severity: Showstopper
Resolution: | Keywords: slist swap
---------------------------+------------------------------------------------

Comment(by andysem):

 The following version of the priv_swap_cache_last method fixes the problem
 for me, although I'm not sure it's acceptable:

 {{{
    void priv_swap_cache_last(slist_impl &other)
    {
       int choice = static_cast< int >(this->empty()) * 2 + static_cast<
 int >(other.empty());
       switch (choice)
       {
       case 0: // both lists are not empty
          {
             node_ptr other_last(other.get_last_node());
             node_ptr this_last(this->get_last_node());
             node_ptr other_bfirst(other.get_root_node());
             node_ptr this_bfirst(this->get_root_node());

             node_algorithms::transfer_after(this_bfirst, other_bfirst,
 other_last);
             node_algorithms::transfer_after(other_bfirst, other_last !=
 other_bfirst? other_last : this_bfirst, this_last);
             node_ptr tmp(this->get_last_node());
             this->set_last_node(other.get_last_node());
             other.set_last_node(tmp);
          }
          break;

       case 1: // other.empty() == true
          other.splice_after(other.before_begin(), *this);
          break;

       case 2: // this->empty() == true
          this->splice_after(this->before_begin(), other);
          break;

       default:; // both lists are empty
       }
    }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/2862#comment:2>
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