@@ -806,13 +806,42 @@ impl<K: Ord, V> BTreeMap<K, V> {
806806 /// ```
807807 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
808808 pub fn remove < Q : ?Sized > ( & mut self , key : & Q ) -> Option < V >
809+ where
810+ K : Borrow < Q > ,
811+ Q : Ord ,
812+ {
813+ self . remove_entry ( key) . map ( |( _, v) | v)
814+ }
815+
816+ /// Removes a key from the map, returning the stored key and value if the key
817+ /// was previously in the map.
818+ ///
819+ /// The key may be any borrowed form of the map's key type, but the ordering
820+ /// on the borrowed form *must* match the ordering on the key type.
821+ ///
822+ /// # Examples
823+ ///
824+ /// Basic usage:
825+ ///
826+ /// ```
827+ /// #![feature(btreemap_remove_entry)]
828+ /// use std::collections::BTreeMap;
829+ ///
830+ /// let mut map = BTreeMap::new();
831+ /// map.insert(1, "a");
832+ /// assert_eq!(map.remove_entry(&1), Some((1, "a")));
833+ /// assert_eq!(map.remove_entry(&1), None);
834+ /// ```
835+ #[ unstable( feature = "btreemap_remove_entry" , issue = "66714" ) ]
836+ pub fn remove_entry < Q : ?Sized > ( & mut self , key : & Q ) -> Option < ( K , V ) >
809837 where
810838 K : Borrow < Q > ,
811839 Q : Ord ,
812840 {
813841 match search:: search_tree ( self . root . as_mut ( ) , key) {
814842 Found ( handle) => Some (
815- OccupiedEntry { handle, length : & mut self . length , _marker : PhantomData } . remove ( ) ,
843+ OccupiedEntry { handle, length : & mut self . length , _marker : PhantomData }
844+ . remove_entry ( ) ,
816845 ) ,
817846 GoDown ( _) => None ,
818847 }
0 commit comments