File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -509,6 +509,13 @@ impl<T: Ord> Extend<T> for BTreeSet<T> {
509
509
}
510
510
}
511
511
512
+ #[ unstable( feature = "extend_ref" , reason = "recently added" ) ]
513
+ impl < ' a , T : ' a + Ord + Copy > Extend < & ' a T > for BTreeSet < T > {
514
+ fn extend < I : IntoIterator < Item =& ' a T > > ( & mut self , iter : I ) {
515
+ self . extend ( iter. into_iter ( ) . cloned ( ) ) ;
516
+ }
517
+ }
518
+
512
519
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
513
520
impl < T : Ord > Default for BTreeSet < T > {
514
521
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
Original file line number Diff line number Diff line change @@ -184,3 +184,31 @@ fn test_show() {
184
184
assert_eq ! ( set_str, "{1, 2}" ) ;
185
185
assert_eq ! ( format!( "{:?}" , empty) , "{}" ) ;
186
186
}
187
+
188
+ #[ test]
189
+ fn test_extend_ref ( ) {
190
+ let mut a = BTreeSet :: new ( ) ;
191
+ a. insert ( 1 ) ;
192
+
193
+ a. extend ( & [ 2 , 3 , 4 ] ) ;
194
+
195
+ assert_eq ! ( a. len( ) , 4 ) ;
196
+ assert ! ( a. contains( & 1 ) ) ;
197
+ assert ! ( a. contains( & 2 ) ) ;
198
+ assert ! ( a. contains( & 3 ) ) ;
199
+ assert ! ( a. contains( & 4 ) ) ;
200
+
201
+ let mut b = BTreeSet :: new ( ) ;
202
+ b. insert ( 5 ) ;
203
+ b. insert ( 6 ) ;
204
+
205
+ a. extend ( & b) ;
206
+
207
+ assert_eq ! ( a. len( ) , 6 ) ;
208
+ assert ! ( a. contains( & 1 ) ) ;
209
+ assert ! ( a. contains( & 2 ) ) ;
210
+ assert ! ( a. contains( & 3 ) ) ;
211
+ assert ! ( a. contains( & 4 ) ) ;
212
+ assert ! ( a. contains( & 5 ) ) ;
213
+ assert ! ( a. contains( & 6 ) ) ;
214
+ }
You can’t perform that action at this time.
0 commit comments