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