15 #ifndef INCG_IRIS_IUTEST_LIST_HPP_CB5AECEA_6147_4A89_BB97_236338CA177E_
16 #define INCG_IRIS_IUTEST_LIST_HPP_CB5AECEA_6147_4A89_BB97_236338CA177E_
20 #if IUTEST_USE_OWN_LIST
32 #if IUTEST_USE_OWN_LIST
43 typedef TN *value_ptr;
44 typedef iu_list_node<TN> _Myt;
59 template<
typename NODE,
typename NODE_PTR,
typename NODE_REF>
60 class iu_list_iterator
62 typedef iu_list_iterator<NODE, NODE_PTR, NODE_REF> _Myt;
64 typedef NODE value_type;
65 typedef NODE_PTR value_ptr;
66 typedef NODE_REF value_ref;
67 typedef value_ptr pointer;
68 typedef value_ref reference;
69 typedef int distance_type;
70 typedef int difference_type;
83 bool operator == (
const _Myt& it)
const {
return this->m_node == it.m_node; }
84 bool operator != (
const _Myt& it)
const {
return this->m_node != it.m_node; }
86 _Myt& operator ++ () { m_node = m_node->next;
return *
this; }
87 _Myt& operator -- () { m_node = m_node->prev;
return *
this; }
92 operator value_ptr () {
return ptr(); }
94 _Myt operator + (
int n)
102 return this->operator +(
static_cast<unsigned int>(n));
106 for(
int i=0; i < n && ret.m_node != NULL; ++i )
108 ret.m_node = ret.m_node->prev;
113 _Myt operator + (
unsigned int n)
116 for(
unsigned int i=0; i < n && ret.m_node != NULL; ++i )
118 ret.m_node = ret.m_node->next;
129 template<
typename NODE>
132 typedef NODE *node_ptr;
133 typedef iu_list<NODE> _Myt;
138 typedef iu_list_iterator<NODE, NODE*, NODE&> iterator;
139 typedef iu_list_iterator<NODE, const NODE*, const NODE&> const_iterator;
148 node_ptr cur = m_node;
162 return m_node == NULL;
166 void sort_insert(node_ptr p)
182 node_ptr next = m_node;
189 node_ptr prev = m_node;
190 node_ptr cur = m_node->next;
210 void push_back(node_ptr p)
223 node_ptr prev = m_node;
224 node_ptr cur = m_node->next;
238 void remove(node_ptr p)
248 if( p->prev == NULL )
258 p->prev->next = p->next;
259 if( p->next != NULL )
261 p->next->prev = p->prev;
264 p->prev = p->next = NULL;
266 void erase(iterator it)
278 for(
unsigned int i=2, n=count(); i<n; ++i )
280 swap(begin() + (i-2), begin() + r(i) % i );
285 void swap(iterator a, iterator b)
291 if( a.ptr() == m_node )
295 else if( b.ptr() == m_node )
300 if( a->next == b.ptr() )
306 if( a->next != NULL )
308 a->next->prev = a.ptr();
310 if( b->prev != NULL )
312 b->prev->next = b.ptr();
315 else if( a->prev == b.ptr() )
321 if( b->next != NULL )
323 b->next->prev = b.ptr();
325 if( a->prev != NULL )
327 a->prev->next = a.ptr();
332 node_ptr tmp = a->next;
338 if( a->next != NULL )
340 a->next->prev = a.ptr();
342 if( b->next != NULL )
344 b->next->prev = b.ptr();
346 if( a->prev != NULL )
348 a->prev->next = a.ptr();
350 if( b->prev != NULL )
352 b->prev->next = b.ptr();
364 return iterator(NULL);
372 return const_iterator(NULL);
380 bool operator () (
const T* lhs,
const T* rhs)
const {
return *lhs == *rhs; }
383 template<
typename FUNC>
384 node_ptr find(node_ptr p, FUNC& f)
const
386 node_ptr cur = m_node;
397 template<
typename FUNC>
398 node_ptr find(FUNC& f)
const
400 node_ptr cur = m_node;
413 node_ptr operator -> () {
return m_node; }
414 node_ptr operator & () {
return m_node; }
415 NODE& operator * () {
return *m_node; }
417 node_ptr operator [] (
int index)
const
419 node_ptr cur = m_node;
420 for(
int i=0; i < index; ++i )
431 bool operator == (node_ptr p)
const {
return m_node == p; }
432 bool operator != (node_ptr p)
const {
return m_node != p; }
443 node_ptr prev = m_node;
444 node_ptr curr = prev->next;
445 while( curr != NULL )
447 assert( prev->next == curr );
448 assert( curr->prev == prev );
460 IUTEST_PRAGMA_WARN_PUSH()
461 IUTEST_PRAGMA_WARN_DISABLE_NOEXCEPT_TPYE()
466 template<typename It>
467 void RandomShuffle(It begin, It last, iuRandom& r)
469 r.shuffle(begin, last);
471 #if IUTEST_USE_OWN_LIST
472 template<
typename Node,
typename Fn>
473 void RandomShuffle(iu_list<Node>& list, Fn& r)
478 template<
typename T,
typename Fn>
479 void RandomShuffle(::std::vector<T>& list, Fn& r)
481 RandomShuffle(list.begin(), list.end(), r);
484 #if IUTEST_USE_OWN_LIST
485 template<
typename Node,
typename Fn>
486 Node* FindList(
const iu_list<Node>& list, Fn& f)
491 template<
typename T,
typename Fn>
492 T FindList(const ::std::vector<T>& list, Fn& f)
494 for(typename ::std::vector<T>::const_iterator it = list.begin(), end = list.end(); it != end; ++it)
509 #if IUTEST_USE_OWN_LIST
511 template<
typename Node,
typename Fn>
512 int CountIf(
const iu_list<Node>& list, Fn f)
515 for(
typename iu_list<Node>::const_iterator it = list.begin(), end=list.end(); it != end; ++it )
527 template<
typename T,
typename Fn>
528 int CountIf(const ::std::vector<T>& list, Fn f)
531 for(typename ::std::vector<T>::const_iterator it = list.begin(), end = list.end(); it != end; ++it)
547 #if IUTEST_USE_OWN_LIST
549 template<
typename Node,
typename Fn>
550 int SumOverList(
const iu_list<Node>& list, Fn f)
553 for(
typename iu_list<Node>::const_iterator it = list.begin(), end=list.end(); it != end; ++it )
555 count += ((*it)->*f)();
562 template<
typename T,
typename Fn>
563 int SumOverList(const ::std::vector<T>& list, Fn f)
566 for(typename ::std::vector<T>::const_iterator it = list.begin(), end = list.end(); it != end; ++it)
568 count += ((*it)->*f)();
579 #if IUTEST_USE_OWN_LIST
581 template<
typename Node,
typename Fn>
582 int CountIfOverList(
const iu_list<Node>& list, Fn f)
585 for(
typename iu_list<Node>::const_iterator it = list.begin(), end=list.end(); it != end; ++it )
597 template<
typename T,
typename Fn>
598 int CountIfOverList(const ::std::vector<T>& list, Fn f)
601 for(typename ::std::vector<T>::const_iterator it = list.begin(), end = list.end(); it != end; ++it)
616 #if IUTEST_USE_OWN_LIST
618 template<
typename Node,
typename Fn>
619 bool AnyOverList(
const iu_list<Node>& list, Fn f)
621 for(
typename iu_list<Node>::const_iterator it = list.begin(), end=list.end(); it != end; ++it )
633 template<
typename T,
typename Fn>
634 bool AnyOverList(const ::std::vector<T>& list, Fn f)
636 for(typename ::std::vector<T>::const_iterator it = list.begin(), end = list.end(); it != end; ++it)
648 IUTEST_PRAGMA_WARN_POP()
#define IUTEST_CXX_NOEXCEPT_SPEC
noexcept specification definition
Definition: iutest_compiler.hpp:811
iutest root namespace
Definition: iutest_charcode.hpp:33