@@ -13,6 +13,7 @@ use core::ops::{BitAnd, BitOr, BitXor, RangeBounds, Sub};
1313
1414use super :: map:: { BTreeMap , Keys } ;
1515use super :: merge_iter:: MergeIterInner ;
16+ use super :: set_val:: SetValZST ;
1617use super :: Recover ;
1718
1819use crate :: alloc:: { Allocator , Global } ;
@@ -81,7 +82,7 @@ pub struct BTreeSet<
8182 T ,
8283 #[ unstable( feature = "allocator_api" , issue = "32838" ) ] A : Allocator + Clone = Global ,
8384> {
84- map : BTreeMap < T , ( ) , A > ,
85+ map : BTreeMap < T , SetValZST , A > ,
8586}
8687
8788#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -135,7 +136,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for BTreeSet<T, A> {
135136#[ must_use = "iterators are lazy and do nothing unless consumed" ]
136137#[ stable( feature = "rust1" , since = "1.0.0" ) ]
137138pub struct Iter < ' a , T : ' a > {
138- iter : Keys < ' a , T , ( ) > ,
139+ iter : Keys < ' a , T , SetValZST > ,
139140}
140141
141142#[ stable( feature = "collection_debug" , since = "1.17.0" ) ]
@@ -158,7 +159,7 @@ pub struct IntoIter<
158159 T ,
159160 #[ unstable( feature = "allocator_api" , issue = "32838" ) ] A : Allocator + Clone = Global ,
160161> {
161- iter : super :: map:: IntoIter < T , ( ) , A > ,
162+ iter : super :: map:: IntoIter < T , SetValZST , A > ,
162163}
163164
164165/// An iterator over a sub-range of items in a `BTreeSet`.
@@ -171,7 +172,7 @@ pub struct IntoIter<
171172#[ derive( Debug ) ]
172173#[ stable( feature = "btree_range" , since = "1.17.0" ) ]
173174pub struct Range < ' a , T : ' a > {
174- iter : super :: map:: Range < ' a , T , ( ) > ,
175+ iter : super :: map:: Range < ' a , T , SetValZST > ,
175176}
176177
177178/// A lazy iterator producing elements in the difference of `BTreeSet`s.
@@ -375,6 +376,11 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
375376 /// `range((Excluded(4), Included(10)))` will yield a left-exclusive, right-inclusive
376377 /// range from 4 to 10.
377378 ///
379+ /// # Panics
380+ ///
381+ /// Panics if range `start > end`.
382+ /// Panics if range `start == end` and both bounds are `Excluded`.
383+ ///
378384 /// # Examples
379385 ///
380386 /// ```
@@ -905,7 +911,7 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
905911 where
906912 T : Ord ,
907913 {
908- self . map . insert ( value, ( ) ) . is_none ( )
914+ self . map . insert ( value, SetValZST :: default ( ) ) . is_none ( )
909915 }
910916
911917 /// Adds a value to the set, replacing the existing element, if any, that is
@@ -1210,7 +1216,7 @@ impl<T: Ord> FromIterator<T> for BTreeSet<T> {
12101216
12111217impl < T : Ord , A : Allocator + Clone > BTreeSet < T , A > {
12121218 fn from_sorted_iter < I : Iterator < Item = T > > ( iter : I , alloc : A ) -> BTreeSet < T , A > {
1213- let iter = iter. map ( |k| ( k, ( ) ) ) ;
1219+ let iter = iter. map ( |k| ( k, SetValZST :: default ( ) ) ) ;
12141220 let map = BTreeMap :: bulk_build_from_sorted_iter ( iter, alloc) ;
12151221 BTreeSet { map }
12161222 }
@@ -1234,7 +1240,7 @@ impl<T: Ord, const N: usize> From<[T; N]> for BTreeSet<T> {
12341240
12351241 // use stable sort to preserve the insertion order.
12361242 arr. sort ( ) ;
1237- let iter = IntoIterator :: into_iter ( arr) . map ( |k| ( k, ( ) ) ) ;
1243+ let iter = IntoIterator :: into_iter ( arr) . map ( |k| ( k, SetValZST :: default ( ) ) ) ;
12381244 let map = BTreeMap :: bulk_build_from_sorted_iter ( iter, Global ) ;
12391245 BTreeSet { map }
12401246 }
@@ -1284,7 +1290,7 @@ pub struct DrainFilter<
12841290 F : ' a + FnMut ( & T ) -> bool ,
12851291{
12861292 pred : F ,
1287- inner : super :: map:: DrainFilterInner < ' a , T , ( ) > ,
1293+ inner : super :: map:: DrainFilterInner < ' a , T , SetValZST > ,
12881294 /// The BTreeMap will outlive this IntoIter so we don't care about drop order for `alloc`.
12891295 alloc : A ,
12901296}
@@ -1319,7 +1325,7 @@ where
13191325
13201326 fn next ( & mut self ) -> Option < T > {
13211327 let pred = & mut self . pred ;
1322- let mut mapped_pred = |k : & T , _v : & mut ( ) | pred ( k) ;
1328+ let mut mapped_pred = |k : & T , _v : & mut SetValZST | pred ( k) ;
13231329 self . inner . next ( & mut mapped_pred, self . alloc . clone ( ) ) . map ( |( k, _) | k)
13241330 }
13251331
0 commit comments