     public mutating func mark() {
         let count = self.buffer.count
         if count > 0 {
-            self.markedIndex = self.endIndex.advanced(by: -1)
+            self.markedIndexOffset = count - 1
         } else {
-            assert(self.markedIndex == nil, "marked index is \(self.markedIndex.debugDescription)")
+            assert(self.markedIndexOffset == nil, "marked index is \(self.markedIndexOffset.debugDescription)")
         }
     }
 


    /// Returns true if the buffer has been marked at all.
    public var hasMark: Bool {
        return self.markedIndex != nil
    }
}

    public func isMarked(index: Index) -> Bool {
        assert(index >= self.startIndex, "index must not be negative")
        precondition(index < self.endIndex, "index \(index) out of range (0..<\(self.buffer.count))")
        if let markedIndexOffset = self.markedIndexOffset {
            return self.startIndex.advanced(by: markedIndexOffset) == index
        } else {
            return false
        }
    }

    /// Returns the index of the marked element.
    public var markedElementIndex: Index? {
        if let markedIndexOffset = self.markedIndexOffset {
            assert(markedIndexOffset >= 0)
            return self.startIndex.advanced(by: markedIndexOffset)
        } else {
            return nil
        }
    }

    /// Returns the marked element.
