hicc_std/std_list.rs
1use hicc::{AbiType, ClassMutPtr};
2use std::iter::Iterator;
3
4hicc::cpp! {
5 #include <list>
6}
7
8hicc::import_class! {
9 /// `std::list`利用迭代器进行增加和删除操作违背`rust`借用规则,将这类操作通过`ListIterMut`实现.
10 #[cpp(class = "template<class T, class Allocator> std::list<T, Allocator>")]
11 pub class list<T> {
12 hicc::cpp! {
13 typedef typename Self::iterator iterator;
14 typedef typename Self::const_iterator const_iterator;
15 typedef typename Self::reverse_iterator reverse_iterator;
16 typedef typename Self::const_reverse_iterator const_reverse_iterator;
17 }
18 /// ```
19 /// use hicc_std::ListInt;
20 /// let list = ListInt::new();
21 /// assert!(list.is_empty());
22 /// ```
23 #[cpp(method = "bool empty() const")]
24 pub fn is_empty(&self) -> bool;
25
26 /// ```
27 /// use hicc_std::ListInt;
28 /// let list = ListInt::new();
29 /// assert_eq!(list.size(), 0);
30 /// ```
31 #[cpp(method = "size_t size() const")]
32 pub fn size(&self) -> usize;
33
34 /// ```
35 /// use hicc_std::ListInt;
36 /// let list = ListInt::new();
37 /// assert!(list.max_size() >= list.size());
38 /// ```
39 #[cpp(method = "size_t max_size() const")]
40 pub fn max_size(&self) -> usize;
41
42 /// ```
43 /// use hicc_std::ListInt;
44 /// let mut list = ListInt::new();
45 /// list.push_back(&1);
46 /// list.clear();
47 /// assert!(list.is_empty());
48 /// ```
49 #[cpp(method = "void clear()")]
50 pub fn clear(&mut self);
51
52 /// ```
53 /// use hicc_std::ListInt;
54 /// let mut list = ListInt::new();
55 /// list.resize(10, &1);
56 /// assert_eq!(list.size(), 10);
57 /// list.iter().for_each(|v| { assert_eq!(v, &1); });
58 /// ```
59 #[cpp(method = "void resize(size_t, const T&)")]
60 pub fn resize(&mut self, n: usize, val: &T);
61
62 /// 如果为空则忽略.
63 /// ```
64 /// use hicc_std::ListInt;
65 /// let mut list = ListInt::new();
66 /// list.push_back(&1);
67 /// list.pop_back();
68 /// assert!(list.is_empty());
69 /// ```
70 pub fn pop_back(&mut self) {
71 if !self.is_empty() {
72 self._pop_back();
73 }
74 }
75 #[cpp(method = "void pop_back()")]
76 fn _pop_back(&mut self);
77
78 /// ```
79 /// use hicc_std::ListInt;
80 /// let mut list = ListInt::new();
81 /// list.push_back(&1);
82 /// assert_eq!(list.front(), Some(&1));
83 /// assert_eq!(list.back(), Some(&1));
84 /// ```
85 #[cpp(method = "void push_back(const T&)")]
86 pub fn push_back(&mut self, val: &T);
87
88 /// 如果为空则忽略.
89 /// ```
90 /// use hicc_std::ListInt;
91 /// let mut list = ListInt::new();
92 /// list.push_back(&1);
93 /// list.pop_front();
94 /// assert!(list.is_empty());
95 /// ```
96 pub fn pop_front(&mut self) {
97 if !self.is_empty() {
98 self._pop_front();
99 }
100 }
101 #[cpp(method = "void pop_front()")]
102 fn _pop_front(&mut self);
103
104 /// ```
105 /// use hicc_std::ListInt;
106 /// let mut list = ListInt::new();
107 /// list.push_front(&1);
108 /// assert_eq!(list.front(), Some(&1));
109 /// assert_eq!(list.back(), Some(&1));
110 /// ```
111 #[cpp(method = "void push_front(const T&)")]
112 pub fn push_front(&mut self, val: &T);
113
114 /// ```
115 /// use hicc_std::ListInt;
116 /// let mut list = ListInt::new();
117 /// list.push_back(&1);
118 /// list.swap(&mut ListInt::new());
119 /// assert!(list.is_empty());
120 /// ```
121 #[cpp(method = "void swap(Self&)")]
122 pub fn swap(&mut self, other: &mut Self);
123
124 /// ```
125 /// use hicc_std::ListInt;
126 /// let mut list = ListInt::new();
127 /// list.assign(10, &1);
128 /// assert_eq!(list.size(), 10);
129 /// list.iter().for_each(|v| assert_eq!(v, &1));
130 /// ```
131 #[cpp(method = "void assign(size_t, const T&)")]
132 pub fn assign(&mut self, ncount: usize, val: &T);
133
134 /// ```
135 /// use hicc_std::ListInt;
136 /// let mut list = ListInt::new();
137 /// list.push_back(&1);
138 /// list.push_back(&2);
139 /// assert_eq!(list.front(), Some(&1));
140 /// assert_eq!(list.back(), Some(&2));
141 /// list.reverse();
142 /// assert_eq!(list.front(), Some(&2));
143 /// assert_eq!(list.back(), Some(&1));
144 /// ```
145 #[cpp(method = "void reverse()")]
146 pub fn reverse(&mut self);
147
148 /// ```
149 /// use hicc_std::ListInt;
150 /// let mut list = ListInt::new();
151 /// assert_eq!(list.back(), None);
152 /// list.push_back(&1);
153 /// assert_eq!(list.back(), Some(&1));
154 /// ```
155 pub fn back(&self) -> Option<T::OutputRef<'_>> {
156 if !self.is_empty() {
157 return Some(unsafe { self._back() });
158 }
159 None
160 }
161 #[cpp(method = "const T& back() const")]
162 unsafe fn _back(&self) -> &T;
163
164 /// ```
165 /// use hicc_std::ListInt;
166 /// let mut list = ListInt::new();
167 /// assert_eq!(list.back_mut(), None);
168 /// list.push_back(&1);
169 /// *list.back_mut().unwrap() = 2;
170 /// assert_eq!(list.back(), Some(&2));
171 ///
172 /// use hicc_std::{string, ListString};
173 /// use hicc::AbiClass;
174 /// let mut list = ListString::new();
175 /// list.push_back(&string::from(c"hello"));
176 /// list.back_mut().unwrap().write(string::from(c"world"));
177 /// assert_eq!(list.back(), Some(string::from(c"world").into_ref()));
178 /// ```
179 pub fn back_mut(&mut self) -> Option<T::OutputRefMut<'_>> {
180 if !self.is_empty() {
181 return Some(unsafe { self._back_mut() });
182 }
183 None
184 }
185 #[cpp(method = "T& back()")]
186 unsafe fn _back_mut(&mut self) -> &mut T;
187
188 /// ```
189 /// use hicc_std::ListInt;
190 /// let mut list = ListInt::new();
191 /// list.push_back(&1);
192 /// assert_eq!(list.back(), Some(&1));
193 /// ```
194 pub fn front(&self) -> Option<T::OutputRef<'_>> {
195 if !self.is_empty() {
196 return Some(unsafe { self._front() });
197 }
198 None
199 }
200 #[cpp(method = "const T& front() const")]
201 unsafe fn _front(&self) -> &T;
202
203 /// ```
204 /// use hicc_std::ListInt;
205 /// let mut list = ListInt::new();
206 /// list.push_back(&1);
207 /// *list.front_mut().unwrap() = 2;
208 /// assert_eq!(list.front(), Some(&2));
209 ///
210 /// use hicc_std::{string, ListString};
211 /// use hicc::AbiClass;
212 /// let mut list = ListString::new();
213 /// list.push_back(&string::from(c"hello"));
214 /// list.front_mut().unwrap().write(string::from(c"world"));
215 /// assert_eq!(list.front(), Some(string::from(c"world").into_ref()));
216 /// ```
217 pub fn front_mut(&mut self) -> Option<T::OutputRefMut<'_>> {
218 if !self.is_empty() {
219 return Some(unsafe { self._front_mut() });
220 }
221 None
222 }
223 #[cpp(method = "T& front()")]
224 unsafe fn _front_mut(&mut self) -> &mut T;
225
226 /// ```
227 /// use hicc_std::ListInt;
228 /// let mut list = ListInt::new();
229 /// list.push_back(&1);
230 /// list.push_back(&2);
231 /// list.push_back(&1);
232 /// list.remove(&1);
233 /// assert_eq!(list.size(), 1);
234 /// assert_eq!(list.front(), Some(&2));
235 /// ```
236 #[cpp(method = "void remove(const T&)")]
237 pub fn remove(&mut self, val: &T);
238
239 hicc::cpp! {
240 static void remove_if(Self& self, std::function<bool(const T&)> comp) {
241 self.remove_if(comp);
242 }
243 }
244 /// ```
245 /// use hicc_std::ListInt;
246 /// let mut list = ListInt::new();
247 /// list.push_back(&1);
248 /// list.push_back(&2);
249 /// list.push_back(&3);
250 /// list.remove_if(|v: &i32| -> bool {
251 /// (v & 1) == 1
252 /// }.into());
253 /// assert_eq!(list.size(), 1);
254 /// assert_eq!(list.front(), Some(&2));
255 /// ```
256 #[cpp(func = "void SelfMethods::remove_if(Self&, std::function<bool(const T&)>)")]
257 pub fn remove_if<'a>(&'a mut self, pred: hicc::Function<fn(&'a T::InputType) -> bool>);
258
259 hicc::cpp! {
260 static void sort(Self& self, std::function<bool(const T&, const T&)> comp) {
261 self.sort(comp);
262 }
263 }
264 /// ```
265 /// use hicc_std::ListInt;
266 /// let mut list = ListInt::new();
267 /// list.push_back(&3);
268 /// list.push_back(&2);
269 /// list.push_back(&1);
270 /// list.sort(|v1: &i32, v2: &i32| -> bool {
271 /// v1 < v2
272 /// }.into());
273 /// let mut it = list.iter();
274 /// assert_eq!(it.next(), Some(&1));
275 /// assert_eq!(it.next(), Some(&2));
276 /// assert_eq!(it.next(), Some(&3));
277 /// assert_eq!(it.next(), None);
278 /// ```
279 //#[cpp(method = "void sort<std::function<bool(const T&, const T&)>>(std::function<bool(const T&, const T&)>)")]
280 #[cpp(func = "void SelfMethods::sort(Self&, std::function<bool(const T&, const T&)>)")]
281 pub fn sort<'a>(&'a mut self, comp: hicc::Function<fn(&'a T::InputType, &'a T::InputType) -> bool>);
282
283 hicc::cpp! {
284 static void merge(Self& self, Self& other, std::function<bool(const T&, const T&)> comp) {
285 if (self.get_allocator() == other.get_allocator()) {
286 self.merge(other, comp);
287 }
288 }
289 }
290 /// 如果不满足如下条件,则忽略
291 /// 1. `self.get_allocator() == other.get_allocator()`.
292 /// ```
293 /// use hicc_std::ListInt;
294 /// let mut list = ListInt::new();
295 /// list.push_back(&3);
296 /// list.push_back(&1);
297 /// let cmp = |v1: &i32, v2: &i32| -> bool {
298 /// v1 < v2
299 /// };
300 /// list.sort(cmp.clone().into());
301 /// let mut other = ListInt::new();
302 /// other.push_back(&4);
303 /// other.push_back(&2);
304 /// other.sort(cmp.clone().into());
305 /// list.merge(&mut other, cmp.into());
306 /// let mut it = list.iter();
307 /// assert!(other.is_empty());
308 /// assert_eq!(it.next(), Some(&1));
309 /// assert_eq!(it.next(), Some(&2));
310 /// assert_eq!(it.next(), Some(&3));
311 /// assert_eq!(it.next(), Some(&4));
312 /// assert_eq!(it.next(), None);
313 /// ```
314 #[cpp(func = "void SelfMethods::merge(Self&, Self&, std::function<bool(const T&, const T&)>)")]
315 pub fn merge<'a>(&'a mut self, other: &mut Self, comp: hicc::Function<fn(&'a T::InputType, &'a T::InputType) -> bool>);
316
317 hicc::cpp! {
318 static void unique(Self& self, std::function<bool(const T&, const T&)> comp) {
319 self.unique(comp);
320 }
321 }
322 /// ```
323 /// use hicc_std::ListInt;
324 /// let mut list = ListInt::new();
325 /// list.push_front(&3);
326 /// list.push_front(&3);
327 /// list.push_front(&1);
328 /// list.push_front(&1);
329 /// let mut n = 0;
330 /// list.unique_with(|v1: &i32, v2: &i32| -> bool {
331 /// v1 == v2
332 /// }.into());
333 /// let mut it = list.iter();
334 /// assert_eq!(it.next(), Some(&1));
335 /// assert_eq!(it.next(), Some(&3));
336 /// assert_eq!(it.next(), None);
337 /// ```
338 #[cpp(func = "void SelfMethods::unique(Self&, std::function<bool(const T&, const T&)>)")]
339 pub fn unique_with<'a>(&'a mut self, comp: hicc::Function<fn(&'a T::InputType, &'a T::InputType) -> bool>);
340
341 /// ```
342 /// use hicc_std::ListInt;
343 /// let mut list = ListInt::new();
344 /// list.push_front(&3);
345 /// list.push_front(&3);
346 /// list.push_front(&1);
347 /// list.push_front(&1);
348 /// list.unique();
349 /// let mut it = list.iter();
350 /// assert_eq!(it.next(), Some(&1));
351 /// assert_eq!(it.next(), Some(&3));
352 /// assert_eq!(it.next(), None);
353 /// ```
354 #[cpp(method = "void unique()")]
355 pub fn unique(&mut self);
356
357 #[cpp(method = "const_iterator begin() const")]
358 unsafe fn begin(&self) -> *mut CppListIter<T>;
359 #[cpp(method = "const_iterator end() const")]
360 unsafe fn end(&self) -> *mut CppListIter<T>;
361
362 // 需要同时调用begin_mut和end_mut, 只能返回指针,否则破坏引用规则.
363 #[cpp(method = "iterator begin()")]
364 unsafe fn begin_mut(&mut self) -> *mut CppListIterMut<T>;
365 #[cpp(method = "iterator end()")]
366 unsafe fn end_mut(&mut self) -> *mut CppListIterMut<T>;
367
368 #[cpp(method = "const_reverse_iterator rbegin() const")]
369 unsafe fn rbegin(&self) -> *mut CppListRevIter<T>;
370 #[cpp(method = "const_reverse_iterator rend() const")]
371 unsafe fn rend(&self) -> *mut CppListRevIter<T>;
372
373 // 需要同时调用rbegin_mut和rend_mut, 只能返回指针,否则破坏引用规则.
374 #[cpp(method = "reverse_iterator rbegin()")]
375 unsafe fn rbegin_mut(&mut self) -> *mut CppListRevIterMut<T>;
376 #[cpp(method = "reverse_iterator rend()")]
377 unsafe fn rend_mut(&mut self) -> *mut CppListRevIterMut<T>;
378
379 hicc::cpp! {
380 static void insert(Self& self, iterator& pos, size_t ncount, const T& val, iterator& end) {
381 pos = self.insert(pos, ncount, val);
382 end = self.end();
383 }
384 }
385 #[cpp(func = "void SelfMethods::insert(Self&, iterator&, size_t, const T&, iterator&)")]
386 unsafe fn insert(&mut self, pos: &mut CppListIterMut<T>, ncount: usize, val: &T, end: &mut CppListIterMut<T>);
387
388 hicc::cpp! {
389 static void splice(Self& self, iterator& pos, Self& other, iterator& end) {
390 if (&self != &other && self.get_allocator() == other.get_allocator()) {
391 self.splice(pos, other);
392 end = self.end();
393 }
394 }
395 }
396 #[cpp(func = "void SelfMethods::splice(Self&, iterator&, Self&, iterator&)")]
397 unsafe fn splice(&mut self, pos: &mut CppListIterMut<T>, other: &mut Self, end: &mut CppListIterMut<T>);
398
399 hicc::cpp! {
400 static void erase(Self& self, iterator& pos, iterator& end) {
401 if (pos != self.end()) {
402 pos = self.erase(pos);
403 end = self.end();
404 }
405 }
406 }
407 #[cpp(func = "void SelfMethods::erase(Self&, iterator&, iterator&)")]
408 unsafe fn erase(&mut self, pos: &mut CppListIterMut<T>, end: &mut CppListIterMut<T>);
409 }
410
411 unsafe impl<T: AbiType + Sync> Send for list<T> {}
412 unsafe impl<T: AbiType + Sync> Sync for list<T> {}
413
414 #[cpp(class = "template<class T, class Allocator> std::list<T, Allocator>::const_iterator")]
415 class CppListIter<T> {
416 hicc::cpp! {
417 static const T& next(Self& self) {
418 return *self++;
419 }
420 }
421 #[cpp(func = "const T& SelfMethods::next(Self&)")]
422 unsafe fn next(&mut self) -> &T;
423 #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
424 fn equal(&self, other: &Self) -> bool;
425 }
426
427 #[cpp(class = "template<class T, class Allocator> std::list<T, Allocator>::iterator")]
428 class CppListIterMut<T> {
429 hicc::cpp! {
430 static T& next(Self& self) {
431 return *self++;
432 }
433 }
434 #[cpp(func = "T& SelfMethods::next(Self&)")]
435 unsafe fn next(&mut self) -> &mut T;
436 #[cpp(func = "bool hicc::make_eq(const Self&, const Self&)")]
437 fn equal(&self, other: &Self) -> bool;
438 }
439
440 #[cpp(class = "template<class T, class Allocator> std::list<T, Allocator>::const_reverse_iterator")]
441 class CppListRevIter<T> {
442 hicc::cpp! {
443 static const T& next(Self& self) {
444 return *self++;
445 }
446 }
447 #[cpp(func = "const T& SelfMethods::next(Self&)")]
448 unsafe fn next(&mut self) -> &T;
449 #[cpp(func = "bool hicc::make_eq(const Self&, const Self&)")]
450 fn equal(&self, other: &Self) -> bool;
451 }
452
453 #[cpp(class = "template<class T, class Allocator> std::list<T, Allocator>::reverse_iterator")]
454 class CppListRevIterMut<T> {
455 hicc::cpp! {
456 static T& next(Self& self) {
457 return *self++;
458 }
459 }
460 #[cpp(func = "T& SelfMethods::next(Self&)")]
461 unsafe fn next(&mut self) -> &mut T;
462 #[cpp(func = "bool hicc::make_eq<Self, Self>(const Self&, const Self&)")]
463 fn equal(&self, other: &Self) -> bool;
464 }
465}
466
467impl<T: AbiType> list<T> {
468 /// ```
469 /// use hicc_std::ListInt;
470 /// let mut list = ListInt::new();
471 /// list.push_back(&1);
472 /// list.push_back(&1);
473 /// assert_eq!(list.iter().count(), 2);
474 /// list.iter().for_each(|v| {assert_eq!(v, &1);});
475 /// ```
476 pub fn iter(&self) -> impl Iterator<Item = T::OutputRef<'_>> {
477 ListIter {
478 beg: unsafe { self.begin() },
479 end: unsafe { self.end() },
480 }
481 }
482 /// ```
483 /// use hicc_std::ListInt;
484 /// let mut list = ListInt::new();
485 /// list.push_back(&1);
486 /// list.push_back(&2);
487 /// list.iter_mut().for_each(|v| *v -= 1);
488 /// assert_eq!(list.front(), Some(&0));
489 /// assert_eq!(list.back(), Some(&1));
490 /// ```
491 pub fn iter_mut(&mut self) -> ListIterMut<'_, T> {
492 let beg = unsafe { self.begin_mut() };
493 let end = unsafe { self.end_mut() };
494 ListIterMut {
495 list: self,
496 beg,
497 end,
498 }
499 }
500 /// ```
501 /// use hicc_std::ListInt;
502 /// let mut list = ListInt::new();
503 /// list.push_back(&1);
504 /// list.push_back(&1);
505 /// assert_eq!(list.rev_iter().count(), 2);
506 /// list.rev_iter().for_each(|v| {assert_eq!(v, &1);});
507 /// ```
508 pub fn rev_iter(&self) -> impl Iterator<Item = T::OutputRef<'_>> {
509 ListRevIter {
510 beg: unsafe { self.rbegin() },
511 end: unsafe { self.rend() },
512 }
513 }
514 /// ```
515 /// use hicc_std::ListInt;
516 /// let mut list = ListInt::new();
517 /// list.push_back(&1);
518 /// list.push_back(&2);
519 /// list.rev_iter_mut().for_each(|v| *v += 1);
520 /// assert_eq!(list.front(), Some(&2));
521 /// assert_eq!(list.back(), Some(&3));
522 /// ```
523 pub fn rev_iter_mut(&mut self) -> impl Iterator<Item = T::OutputRefMut<'_>> {
524 let beg = unsafe { self.rbegin_mut() };
525 let end = unsafe { self.rend_mut() };
526 ListRevIterMut { beg, end }
527 }
528}
529
530/// 对应`std::list<T>::const_iterator`
531struct ListIter<'a, T: AbiType + 'static> {
532 beg: ClassMutPtr<'a, CppListIter<T>>,
533 end: ClassMutPtr<'a, CppListIter<T>>,
534}
535
536impl<'a, T: AbiType + 'static> Iterator for ListIter<'a, T> {
537 type Item = T::OutputRef<'a>;
538 fn next(&mut self) -> Option<Self::Item> {
539 if !self.beg.equal(&self.end) {
540 return Some(unsafe { self.beg.as_deref_mut().next() });
541 }
542 None
543 }
544}
545
546/// 对应`std::list<T>::const_reverse_iterator`
547struct ListRevIter<'a, T: AbiType + 'static> {
548 beg: ClassMutPtr<'a, CppListRevIter<T>>,
549 end: ClassMutPtr<'a, CppListRevIter<T>>,
550}
551
552impl<'a, T: AbiType + 'static> Iterator for ListRevIter<'a, T> {
553 type Item = T::OutputRef<'a>;
554 fn next(&mut self) -> Option<Self::Item> {
555 if !self.beg.equal(&self.end) {
556 return Some(unsafe { self.beg.as_deref_mut().next() });
557 }
558 None
559 }
560}
561
562/// 对应`std::list<T>::iterator`
563pub struct ListIterMut<'a, T: AbiType + 'static> {
564 list: &'a mut list<T>,
565 beg: ClassMutPtr<'a, CppListIterMut<T>>,
566 end: ClassMutPtr<'a, CppListIterMut<T>>,
567}
568
569impl<'a, T: AbiType + 'static> Iterator for ListIterMut<'a, T> {
570 type Item = T::OutputRefMut<'a>;
571 fn next(&mut self) -> Option<Self::Item> {
572 if !self.beg.equal(&self.end) {
573 return Some(unsafe { self.beg.as_deref_mut().next() });
574 }
575 None
576 }
577}
578
579/// 对应`std::list<T>::reverse_iterator`
580struct ListRevIterMut<'a, T: AbiType + 'static> {
581 beg: ClassMutPtr<'a, CppListRevIterMut<T>>,
582 end: ClassMutPtr<'a, CppListRevIterMut<T>>,
583}
584
585impl<'a, T: AbiType + 'static> Iterator for ListRevIterMut<'a, T> {
586 type Item = T::OutputRefMut<'a>;
587 fn next(&mut self) -> Option<Self::Item> {
588 if !self.beg.equal(&self.end) {
589 return Some(unsafe { self.beg.as_deref_mut().next() });
590 }
591 None
592 }
593}
594
595impl<T: AbiType + 'static> ListIterMut<'_, T> {
596 /// 调用`std::list::insert`并将当前节点更新为其返回值.
597 /// ```
598 /// use hicc_std::ListInt;
599 /// let mut list = ListInt::new();
600 /// let mut it = list.iter_mut();
601 /// it.insert(2, &1);
602 /// assert_eq!(it.next(), Some(&mut 1));
603 /// assert_eq!(it.next(), Some(&mut 1));
604 /// assert_eq!(it.next(), None);
605 /// it.insert(2, &2);
606 /// assert_eq!(it.next(), Some(&mut 2));
607 /// assert_eq!(it.next(), Some(&mut 2));
608 /// assert_eq!(it.next(), None);
609 /// ```
610 pub fn insert(&mut self, ncount: usize, val: &T::InputType) {
611 unsafe {
612 self.list.insert(&mut self.beg, ncount, val, &mut self.end);
613 }
614 }
615
616 /// 如果满足以下调用`std::list::splice`.
617 /// 1. `self`和`other`不同.
618 /// 2. `self.get_allocator() == other.get_allocator`.
619 /// ```
620 /// use hicc_std::ListInt;
621 /// let mut list = ListInt::new();
622 /// let mut other = ListInt::new();
623 /// other.push_back(&1);
624 /// let mut it = list.iter_mut();
625 /// it.splice(&mut other);
626 /// assert!(other.is_empty());
627 /// assert_eq!(it.next(), None);
628 /// let mut it = list.iter();
629 /// assert_eq!(it.next(), Some(&1));
630 /// assert_eq!(it.next(), None);
631 /// ```
632 pub fn splice(&mut self, other: &mut list<T>) {
633 unsafe {
634 self.list.splice(&mut self.beg, other, &mut self.end);
635 }
636 }
637
638 /// 如果当前节点有效调用`std::list::erase`并更新为其返回值.
639 /// ```
640 /// use hicc_std::ListInt;
641 /// let mut list = ListInt::new();
642 /// let mut it = list.iter_mut();
643 /// it.remove();
644 /// it.insert(2, &1);
645 /// it.remove();
646 /// it.remove();
647 /// assert!(list.is_empty());
648 /// ```
649 pub fn remove(&mut self) {
650 unsafe {
651 self.list.erase(&mut self.beg, &mut self.end);
652 }
653 }
654}