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