     }
   }
   
+  /// Appends the elements of `newElements` to the `CircularArray`.
+  ///
+  /// - Complexity: O(*length of `newElements`*).
   public mutating func appendContentsOf<
     C : CollectionType where C.Generator.Element == Element
   >(newElements: C) {

    }
  }
  
  public mutating func prependContentsOf<
    C : CollectionType where C.Generator.Element == Element
  >(newElements: C) {
    reserveCapacity(numericCast(newElements.count))
    for element in newElements.reverse() {
      storage_.prepend(element)
    }
  }
  
  public mutating func append(newElement: Element) {
    makeMutableAndUnique()
    storage_.append(newElement)
  }
  
  public mutating func appendContentsOf<
    S : SequenceType where S.Generator.Element == Element
  >(newElements: S) {

      storage_.removeAll(keepCapacity: keepCapacity)
    }
  }
  
  /// Creates a new storage if this circular array is not backed by a
  /// uniquely-referenced mutable storage.
  mutating func makeUniqueMutableStorage() {
    if !isUniquelyReferencedNonObjC(&storage_) {
      storage_ = CircularArrayBuffer(buffer: storage_)
    }
  }
}

extension CircularArray : Indexable, MutableIndexable {
  /// A type that represents a valid position in the collection.
  ///
  /// Valid indices consist of the position of every element and a
  /// "past the end" position that's not valid for use as a subscript.
  public typealias Index = Int
  
  /// The position of the first element in a non-empty collection.
  ///
  /// In an empty collection, `startIndex == endIndex`.
  public var startIndex: Index {
    return 0
  }
  
  /// A "past-the-end" element index; the successor of the last valid
  /// subscript argument.
  public var endIndex: Index {
    return storage_.count
  }
  
  /// Access the `index`th element.
  ///
  /// - Complexity: O(1).
  public subscript(index: Index) -> Element {
    get {
      checkIndex(index)
      return storage_[index]
    } set {
      checkIndex(index)
      makeUniqueMutableStorage()
      storage_[index] = newValue
    }
  }
  
  /// Checks that the given `index` is valid.
  func checkIndex(index: Index) {
    precondition(index >= startIndex && index <= endIndex, "index out of range")
  }
}

extension CircularArray
  : CustomStringConvertible, CustomDebugStringConvertible {
  
  /// A textual representation of `self`.
  public var description: String {
    return Array(self).description
  }
  
  /// A textual representation of `self`, suitable for debugging.
  public var debugDescription: String {
    return "CircularArray(\(description))"
  }
}

extension CircularArray {
  /// Call `body(p)`, where `p` is a pointer to the `CircularArray`'s
  /// contiguous storage.
  ///
  /// Often, the optimizer can eliminate bounds checks within an
  /// array algorithm, but when that fails, invoking the
  /// same algorithm on `body`'s argument lets you trade safety for
  /// speed.
  public func withUnsafeBufferPointer<R>(
    @noescape body: (UnsafeBufferPointer<Element>) throws -> R
    ) rethrows -> R {
      return try storage_.withUnsafeBufferPointer(body)
  }
  
  /// Call `body(p)`, where `p` is a pointer to the `CircularArray`'s
  /// mutable contiguous storage.
  ///
  /// Often, the optimizer can eliminate bounds- and uniqueness-checks
  /// within an array algorithm, but when that fails, invoking the
  /// same algorithm on `body`'s argument lets you trade safety for
  /// speed.
  ///
  /// - Warning: Do not rely on anything about `self` (the `CircularArray`
  ///   that is the target of this method) during the execution of
  ///   `body`: it may not appear to have its correct value.  Instead,
  ///   use only the `UnsafeMutableBufferPointer` argument to `body`.
  public func withUnsafeMutableBufferPointer<R>(
    @noescape body: (UnsafeMutableBufferPointer<Element>) throws -> R
    ) rethrows -> R {
      return try storage_.withUnsafeMutableBufferPointer(body)
  }
}

/// Returns `true` if these circular arrays contain the same elements.
@warn_unused_result
public func ==<Element : Equatable>(
  lhs: CircularArray<Element>, rhs: CircularArray<Element>
