@@ -17,7 +17,8 @@ use core::ops::Index;
1717use core:: { fmt, intrinsics, mem, ptr} ;
1818
1919use borrow:: Borrow ;
20- use Bound :: { self , Excluded , Included , Unbounded } ;
20+ use Bound :: { Excluded , Included , Unbounded } ;
21+ use range:: RangeArgument ;
2122
2223use super :: node:: { self , Handle , NodeRef , marker} ;
2324use super :: search;
@@ -654,10 +655,12 @@ impl<K: Ord, V> BTreeMap<K, V> {
654655 self . fix_right_edge ( ) ;
655656 }
656657
657- /// Constructs a double-ended iterator over a sub-range of elements in the map, starting
658- /// at min, and ending at max. If min is `Unbounded`, then it will be treated as "negative
659- /// infinity", and if max is `Unbounded`, then it will be treated as "positive infinity".
660- /// Thus range(Unbounded, Unbounded) will yield the whole collection.
658+ /// Constructs a double-ended iterator over a sub-range of elements in the map.
659+ /// The simplest way is to use the range synax `min..max`, thus `range(min..max)` will
660+ /// yield elements from min (inclusive) to max (exclusive).
661+ /// The range may also be entered as `(Bound<T>, Bound<T>)`, so for example
662+ /// `range((Excluded(4), Included(10)))` will yield a left-exclusive, right-inclusive
663+ /// range from 4 to 10.
661664 ///
662665 /// # Examples
663666 ///
@@ -667,26 +670,25 @@ impl<K: Ord, V> BTreeMap<K, V> {
667670 /// #![feature(btree_range, collections_bound)]
668671 ///
669672 /// use std::collections::BTreeMap;
670- /// use std::collections::Bound::{ Included, Unbounded} ;
673+ /// use std::collections::Bound::Included;
671674 ///
672675 /// let mut map = BTreeMap::new();
673676 /// map.insert(3, "a");
674677 /// map.insert(5, "b");
675678 /// map.insert(8, "c");
676- /// for (&key, &value) in map.range(Included(&4), Included(&8)) {
679+ /// for (&key, &value) in map.range(( Included(&4), Included(&8) )) {
677680 /// println!("{}: {}", key, value);
678681 /// }
679- /// assert_eq!(Some((&5, &"b")), map.range(Included(&4), Unbounded ).next());
682+ /// assert_eq!(Some((&5, &"b")), map.range(4.. ).next());
680683 /// ```
681684 #[ unstable( feature = "btree_range" ,
682685 reason = "matches collection reform specification, waiting for dust to settle" ,
683686 issue = "27787" ) ]
684- pub fn range < Min : ?Sized + Ord , Max : ?Sized + Ord > ( & self ,
685- min : Bound < & Min > ,
686- max : Bound < & Max > )
687- -> Range < K , V >
688- where K : Borrow < Min > + Borrow < Max >
687+ pub fn range < T : ?Sized , R > ( & self , range : R ) -> Range < K , V >
688+ where T : Ord , K : Borrow < T > , R : RangeArgument < T >
689689 {
690+ let min = range. start ( ) ;
691+ let max = range. end ( ) ;
690692 let front = match min {
691693 Included ( key) => {
692694 match search:: search_tree ( self . root . as_ref ( ) , key) {
@@ -745,25 +747,26 @@ impl<K: Ord, V> BTreeMap<K, V> {
745747 }
746748 }
747749
748- /// Constructs a mutable double-ended iterator over a sub-range of elements in the map, starting
749- /// at min, and ending at max. If min is `Unbounded`, then it will be treated as "negative
750- /// infinity", and if max is `Unbounded`, then it will be treated as "positive infinity".
751- /// Thus range(Unbounded, Unbounded) will yield the whole collection.
750+ /// Constructs a mutable double-ended iterator over a sub-range of elements in the map.
751+ /// The simplest way is to use the range synax `min..max`, thus `range(min..max)` will
752+ /// yield elements from min (inclusive) to max (exclusive).
753+ /// The range may also be entered as `(Bound<T>, Bound<T>)`, so for example
754+ /// `range((Excluded(4), Included(10)))` will yield a left-exclusive, right-inclusive
755+ /// range from 4 to 10.
752756 ///
753757 /// # Examples
754758 ///
755759 /// Basic usage:
756760 ///
757761 /// ```
758- /// #![feature(btree_range, collections_bound )]
762+ /// #![feature(btree_range)]
759763 ///
760764 /// use std::collections::BTreeMap;
761- /// use std::collections::Bound::{Included, Excluded};
762765 ///
763766 /// let mut map: BTreeMap<&str, i32> = ["Alice", "Bob", "Carol", "Cheryl"].iter()
764767 /// .map(|&s| (s, 0))
765768 /// .collect();
766- /// for (_, balance) in map.range_mut(Included( "B"), Excluded( "Cheryl") ) {
769+ /// for (_, balance) in map.range_mut("B".. "Cheryl") {
767770 /// *balance += 100;
768771 /// }
769772 /// for (name, balance) in &map {
@@ -773,12 +776,11 @@ impl<K: Ord, V> BTreeMap<K, V> {
773776 #[ unstable( feature = "btree_range" ,
774777 reason = "matches collection reform specification, waiting for dust to settle" ,
775778 issue = "27787" ) ]
776- pub fn range_mut < Min : ?Sized + Ord , Max : ?Sized + Ord > ( & mut self ,
777- min : Bound < & Min > ,
778- max : Bound < & Max > )
779- -> RangeMut < K , V >
780- where K : Borrow < Min > + Borrow < Max >
779+ pub fn range_mut < T : ?Sized , R > ( & mut self , range : R ) -> RangeMut < K , V >
780+ where T : Ord , K : Borrow < T > , R : RangeArgument < T >
781781 {
782+ let min = range. start ( ) ;
783+ let max = range. end ( ) ;
782784 let root1 = self . root . as_mut ( ) ;
783785 let root2 = unsafe { ptr:: read ( & root1) } ;
784786
0 commit comments