Ejemplo n.º 1
0
Archivo: queue.hpp Proyecto: ebnn/retro
    /*! Retroactively revert a previous operation.
     *  \param t The time point to revert.
     */
    void revert(const time_point &t)
    {
      if (t.operation() == queue::push)
      {
        // This element was never pushed.
        --size_;

        // If t occurs before front, then that means we've previously popped an
        // element that no longer exists, so it should have popped the element
        // after it. Hence, move the front to its successor.
        if (t.it->second)
        {
          move_front_succ();
        }
        else if (front_ == t.it)
        {
          // We're removing the front, so move it right to ensure validity.
          move_front_succ();
        }

        // Remove the element corresponding to the push.
        data_.erase(t.it);
      }
      else
      {
        move_front_pred();
        ++size_; // One less pop means the size increases by 1
      }
    }