         let dst = buffer.elements
         let src = self.elements
         if self.start + self.count <= self.capacity {
-            dst.moveInitializeFrom(src.advancedBy(start), count: count)
+            dst.moveInitializeFrom(src.advanced(by: start), count: count)
         }
         else {
             let c = self.capacity - self.start
-            dst.moveInitializeFrom(src.advancedBy(self.start), count: c)
-            dst.advancedBy(c).moveInitializeFrom(src, count: self.count - c)
+            dst.moveInitializeFrom(src.advanced(by: self.start), count: c)
+            dst.advanced(by: c).moveInitializeFrom(src, count: self.count - c)
         }
         self.count = 0
         return buffer
     }
-
-
+    
+    
     /// Returns the storage buffer index for a deque index.
     internal func bufferIndexForDequeIndex(index: Int) -> Int {
         let i = start + index
         if i >= capacity { return i - capacity }
         return i
     }
-
+    
     /// Returns the deque index for a storage buffer index.
     internal func dequeIndexForBufferIndex(i: Int) -> Int {
         if i >= start {

        }
        return capacity - start + i
    }

    internal var isFull: Bool { return count == capacity }

    internal subscript(index: Int) -> Element {
        get {
            assert(index >= 0 && index < count)
            let i = bufferIndexForDequeIndex(index)
            return elements.advancedBy(i).memory
        }
        set {
            assert(index >= 0 && index < count)
            let i = bufferIndexForDequeIndex(index)
            elements.advancedBy(i).memory = newValue
        }
    }

    internal func prepend(element: Element) {
        precondition(count < capacity)
        let i = start == 0 ? capacity - 1 : start - 1
        elements.advancedBy(i).initialize(element)
        self.start = i
        self.count += 1
    }

    internal func popFirst() -> Element? {
        guard count > 0 else { return nil }
        let first = elements.advancedBy(start).move()
        self.start = bufferIndexForDequeIndex(1)
        self.count -= 1
        return first
    }

    internal func append(element: Element) {
        precondition(count < capacity)
        let endIndex = bufferIndexForDequeIndex(count)
        elements.advancedBy(endIndex).initialize(element)
        self.count += 1
    }

    internal func popLast() -> Element? {
        guard count > 0 else { return nil }
        let lastIndex = bufferIndexForDequeIndex(count - 1)
        let last = elements.advancedBy(lastIndex).move()
        self.count -= 1
        return last
    }

    /// Create a gap of `length` uninitialized slots starting at `index`.
    /// Existing elements are moved out of the way.
    /// You are expected to fill the gap by initializing all slots in it after calling this method.

public struct Deque<Element> {
    /// The storage for this deque.
    internal private(set) var buffer: DequeBuffer<Element>
    
    /// Initializes an empty deque.
    public init() {
        buffer = DequeBuffer()
