Update contrib.
1 /***************************************************************************
3 * alg_test.h - common definitions for algorithms tests
5 * $Id: alg_test.h 349021 2005-11-25 20:32:27Z sebor $
7 ***************************************************************************
9 * Copyright (c) 1994-2005 Quovadx, Inc., acting through its Rogue Wave
10 * Software division. Licensed under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance with the
12 * License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0. Unless required by
14 * applicable law or agreed to in writing, software distributed under
15 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
16 * CONDITIONS OF ANY KIND, either express or implied. See the License
17 * for the specific language governing permissions and limitations under
20 **************************************************************************/
22 #ifndef _RWSTD_ALG_TEST_H_INCLUDED
23 #define _RWSTD_ALG_TEST_H_INCLUDED
27 #include <cassert> // for assert()
33 // defining macro for var
34 #define n_total_op_assign_ (*Getn_total_op_assign_())
35 #define n_total_op_eq_ (*Getn_total_op_eq_())
36 #define gen_ (* Get_gen_())
37 // objects of class X maintain a count of their instances in existence,
38 // the number of defaut and copy ctor calls, assignment operators, and
39 // the number of calls to operator==() and operator<()
42 const int id_; // a unique non-zero id of the object
43 int origin_; // id of the original object that this
44 // is a (perhaps indirect) copy of (id_
45 // when this is the original)
46 int src_id_; // id of the object that this is a direct
47 // copy of (id_ when this the original)
48 int val_; // object's value
50 // number of times the object has been copied into another object,
51 // regardless of whether the operation threw an exception or not
52 _RWSTD_SIZE_T n_copy_ctor_;
54 // number of times the object's assignment operator has been invoked,
55 // regardless of whether the operation threw an exception or not
56 _RWSTD_SIZE_T n_op_assign_;
58 // number of times the object's operator== was invoked
59 // regardless of whether the operation threw an exception
60 _RWSTD_SIZE_T n_op_eq_;
62 // number of times the object's operator< was invoked
63 // regardless of whether the operation threw an exception
64 _RWSTD_SIZE_T n_op_lt_;
66 static _RWSTD_SIZE_T count_; // number of objects in existence (>= 0)
67 static int id_gen_; // generates a unique non-zero id
68 _TEST_EXPORT static int (*_gen_)(); // extern "C++" int (*)()
70 _TEST_EXPORT static _RWSTD_SIZE_T n_total_def_ctor_; // number of default ctor calls
71 _TEST_EXPORT static _RWSTD_SIZE_T n_total_copy_ctor_; // ... copy ctors ...
72 _TEST_EXPORT static _RWSTD_SIZE_T n_total_dtor_; // ... dtors ...
73 //new chnage decl of member var
74 _TEST_EXPORT static _RWSTD_SIZE_T _n_total_op_assign_; // ... assignment operators ...
75 _TEST_EXPORT static _RWSTD_SIZE_T _n_total_op_eq_; // ... equality operators ...
76 _TEST_EXPORT static _RWSTD_SIZE_T n_total_op_lt_; // ... operators <= ...
78 // classes thrown from the respective functions
79 struct Exception { int id_; };
80 struct DefCtor: Exception { };
81 struct CopyCtor: Exception { };
82 struct Dtor: Exception { };
83 struct OpAssign: Exception { };
84 struct OpEq: Exception { };
85 struct OpLt: Exception { };
87 // throw object's `id' wrapped in the appropriate struct when the
88 // corresponding n_total_xxx_ counter reaches the value pointed to
89 // by the respective pointer below
90 static _RWSTD_SIZE_T* def_ctor_throw_ptr_;
91 static _RWSTD_SIZE_T* copy_ctor_throw_ptr_;
92 static _RWSTD_SIZE_T* dtor_throw_ptr_;
93 static _RWSTD_SIZE_T* op_assign_throw_ptr_;
94 static _RWSTD_SIZE_T* op_eq_throw_ptr_;
95 static _RWSTD_SIZE_T* op_lt_throw_ptr_;
97 // objects to which the pointers above initally point
98 static _RWSTD_SIZE_T def_ctor_throw_count_;
99 static _RWSTD_SIZE_T copy_ctor_throw_count_;
100 static _RWSTD_SIZE_T dtor_throw_count_;
101 static _RWSTD_SIZE_T op_assign_throw_count_;
102 static _RWSTD_SIZE_T op_eq_throw_count_;
103 static _RWSTD_SIZE_T op_lt_throw_count_;
107 _TEST_EXPORT X (const X&);
111 _TEST_EXPORT X& operator= (const X&);
113 _TEST_EXPORT bool operator== (const X&) const;
114 _TEST_EXPORT bool operator< (const X&) const;
116 // the following operators are not declared or defined in order
117 // to detect any unwarranted assumptions made in algorithms
118 // bool operator!= (const X &rhs) const;
119 // bool operator> (const X &rhs) const;
120 // bool operator>= (const X &rhs) const;
121 // bool operator<= (const X &rhs) const;
122 // X operator- () const;
123 // X operator+ () const;
126 is_count (_RWSTD_SIZE_T copy_ctor,
127 _RWSTD_SIZE_T op_assign,
129 _RWSTD_SIZE_T op_lt) const;
131 _TEST_EXPORT static bool
132 is_total (_RWSTD_SIZE_T count,
133 _RWSTD_SIZE_T n_def_ctor,
134 _RWSTD_SIZE_T n_copy_ctor,
135 _RWSTD_SIZE_T n_op_assign,
136 _RWSTD_SIZE_T n_op_eq,
137 _RWSTD_SIZE_T n_op_lt);
139 _TEST_EXPORT static void reset_totals ();
141 // construct an array of objects of type X each initialized
142 // from the corresponding element of the character array
143 static X* from_char (const char*, _RWSTD_SIZE_T = ~0UL);
145 // returns -1 when less, 0 when same, or +1 when the array
146 // of X objects is greater than the character string
147 static int compare (const X*, const char*, _RWSTD_SIZE_T = ~0UL);
148 static int compare (const char*, const X*, _RWSTD_SIZE_T = ~0UL);
150 // returns -1 when less, 0 when same, or +1 when the first
151 // array of X objects is greater than the second array
152 static int compare (const X*, const X*, _RWSTD_SIZE_T);
156 struct _TEST_EXPORT UnaryPredicate
158 // total number of times operator() was invoked
159 static _RWSTD_SIZE_T n_total_op_fcall_;
163 UnaryPredicate (const UnaryPredicate&);
165 UnaryPredicate& operator= (const UnaryPredicate&);
167 virtual ~UnaryPredicate ();
169 virtual bool operator()(const X&) const;
173 struct _TEST_EXPORT BinaryPredicate
175 // total number of times operator() was invoked
176 static _RWSTD_SIZE_T n_total_op_fcall_;
180 BinaryPredicate (bool = false);
182 BinaryPredicate (const BinaryPredicate&);
184 BinaryPredicate& operator= (const BinaryPredicate&);
186 virtual ~BinaryPredicate ();
188 virtual bool operator()(const X&, const X&) const;
192 class _TEST_EXPORT tempstr;
194 // converts a sequence of objects of type X to a tempstr object
195 // in the format "[%p0, %p1): { x0, >x1<, ..., xN - 1 } where N
196 // is defined as: N = (X*)p1 - (X*)p0
197 // the last argument, if non-negative, indicates the index of the
198 // element enclosed in between the '>' and '<' characters
199 _TEST_EXPORT void to_string (tempstr*, const X*, const X*, int = -1);
202 // generate a unique sequential number starting from 0
203 _TEST_EXPORT int gen_seq ();
205 // generate numbers in the sequence 0, 0, 1, 1, 2, 2, 3, 3, etc...
206 _TEST_EXPORT int gen_seq_2lists ();
208 // generate a sequence of subsequences (i.e., 0, 1, 2, 3, 4, 0, 1, 2, etc...)
209 _TEST_EXPORT int gen_subseq ();
211 // wrapper around a (possibly) extern "C" int rand()
213 _TEST_EXPORT int gen_rnd ();
216 // computes an integral log2
217 inline unsigned ilog2 (unsigned long n)
226 // computes an integral log10
227 inline unsigned ilog10 (unsigned long n)
236 // returns true iff a sequence of (not necessarily unique) values
237 // is sorted in an ascending order
238 template <class InputIterator>
239 inline bool is_sorted_lt (InputIterator first, InputIterator last)
244 for (InputIterator prev (first); ++first != last; prev = first) {
253 // returns true iff a sequence of (not necessarily unique) values
254 // is sorted in a descending order
255 template <class InputIterator>
256 inline bool is_sorted_gt (InputIterator first, InputIterator last)
261 for (InputIterator prev (first); ++first != last; prev = first) {
270 // type used to exercise that algorithms do not apply operators
271 // to function objects the latter are not required to define
272 struct conv_to_bool {
274 static conv_to_bool make (bool val) {
280 operator bool () const {
285 bool operator!() const
294 void operator&& (const conv_to_bool&, bool);
295 void operator&& (bool, const conv_to_bool&);
296 void operator|| (const conv_to_bool&, bool);
297 void operator|| (bool, const conv_to_bool&);
299 // element-type prototypes to exercise container requirements
302 // meets requirements listed at 25, p7
305 conv_to_bool operator() (const T &a) const {
307 return conv_to_bool::make (true);
312 // meets requirements listed at 25, p8
314 struct binary_predicate {
315 conv_to_bool operator() (const T &a, const T &b) const {
318 return conv_to_bool::make (true);
323 // meets requirements listed at 25.2.3, p2
326 typedef T argument_type;
327 typedef argument_type& reference;
329 reference operator() (const argument_type&) const {
330 return _RWSTD_REINTERPRET_CAST (reference,
331 _RWSTD_CONST_CAST (func*, this)->dummy);
339 // meets requirements listed at 25.2.3, p2
342 typedef T argument_type;
343 typedef argument_type& reference;
345 reference operator() (const argument_type&,
346 const argument_type&) const {
347 return _RWSTD_REINTERPRET_CAST (reference,
348 _RWSTD_CONST_CAST (binary_func*, this)->dummy);
356 // a base-class to extend the requirements classes from
358 enum { no_ctor = 0, def_ctor = 1, cpy_ctor = 2 };
360 template <int c = no_ctor>
368 // struct s added to prevent gcc warning: base<no_ctor> has a private
369 // constructor and no friends
375 void operator= (base&);
380 struct base<def_ctor>
382 base () : unused (0) { }
386 void operator= (base&);
389 // unused member prevents bogus HP aCC warnings (see Onyx #23561)
395 struct base<cpy_ctor>
397 // explicitly specifying redundant template parameters to work
398 // around a SunPro 5.2 bug (see Onyx #24260)
399 base (const base<cpy_ctor> &rhs): unused (rhs.unused) { }
404 void operator= (base&);
406 // unused member prevents bogus HP aCC warnings (see Onyx #23561)
412 struct base<(def_ctor | cpy_ctor)>
414 base (): unused (0) { }
416 // explicitly specifying redundant template parameters to work
417 // around a SunPro 5.2 bug (see Onyx #24260)
418 base (const base<(def_ctor | cpy_ctor)> &rhs): unused (rhs.unused) { }
422 void operator= (base&);
424 // unused member prevents bogus HP aCC warnings (see Onyx #23561)
430 struct eq_comp: T { };
434 inline bool operator== (const eq_comp<T>&, const eq_comp<T>&)
441 struct lt_comp: T { };
445 inline bool operator< (const lt_comp<T>&, const lt_comp<T>&)
456 assign& operator= (const assign& rhs) {
461 // unused member prevents bogus HP aCC warnings (see Onyx #23561)
466 // conversion structs
468 // struct split into 2 to eliminate the following g++ 2.95.2 warning:
469 // warning: choosing `convert<T>::operator U&()' over
470 // `convert<T>::operator const U&() const'
472 template <class T, class U>
476 return _RWSTD_REINTERPRET_CAST (U&, *this);
481 template <class T, class U>
484 operator const U& () const {
485 return _RWSTD_REINTERPRET_CAST (const U&, *this);
490 #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
492 struct DummyBase { };
494 # define ITER_BASE(ign1, ign2, ign3, ign4, ign5) DummyBase
495 #else // if defined (_RWSTD_NO_CLASS_PARTIAL_SPEC)
496 // when partial specialization isn't supported
497 # define ITER_BASE(Cat, T, Dist, Ptr, Ref) \
498 std::iterator<Cat, T, Dist, Ptr, Ref >
499 #endif // _RWSTD_NO_CLASS_PARTIAL_SPEC
502 // satisfies the requirements in 24.1.1 [lib.input.iterators]
504 struct InputIter: ITER_BASE (std::input_iterator_tag, T, int, T*, T&)
506 typedef T value_type;
507 typedef value_type* pointer;
508 typedef value_type& reference;
509 typedef int difference_type;
510 typedef std::input_iterator_tag iterator_category;
512 // body shared by all copies of the same InputIter specialization
513 // to detect algorithms that pass through the same interator more
514 // than once (disallowed by 24.1.1, p3)
516 const value_type *cur_;
517 const value_type *beg_;
518 const value_type *end_;
521 Shared (const value_type *cur,
522 const value_type *beg,
523 const value_type *end)
524 : cur_ (cur), beg_ (beg), end_ (end), ref_ (1) { }
527 cur_ = beg_ = end_ = 0;
532 Shared (const Shared&); // not defined
533 void operator= (const Shared&); // not defined
537 // InputIterators are not default constructible
538 InputIter (const value_type *cur,
539 const value_type *beg,
540 const value_type *end)
541 : ptr_ (new Shared (cur, beg, end)), cur_ (cur) { }
543 InputIter (const InputIter &rhs)
544 : ptr_ (rhs.ptr_), cur_ (rhs.cur_) {
552 if (0 == --ptr_->ref_) // decrement the reference count
558 InputIter& operator= (const InputIter &rhs) {
559 assert (rhs == rhs); // assert `rhs' is valid
562 if (0 == --ptr_->ref_)
575 bool operator== (const InputIter &rhs) const {
576 // assert that both arguments are in the domain of operator==()
577 // i.e., that no copy of *this or `rhs' has been incremented
578 // and that no copy passed through this value of the iterator
581 assert (cur_ == ptr_->cur_);
583 assert (0 != rhs.ptr_);
584 assert (rhs.cur_ == rhs.ptr_->cur_);
586 return cur_ == rhs.cur_;
589 bool operator!= (const InputIter &rhs) const {
590 return !(*this == rhs);
593 // returning const-reference rather than a value in order
594 // not to impose the CopyConstructible requirement on T
595 // and to disallow constructs like *InputIter<T>() = T()
596 const value_type& operator* () const {
597 assert (*this == *this); // assert *this is valid
598 assert (cur_ < ptr_->end_); // assert *this is dereferenceable
602 _RWSTD_OPERATOR_ARROW(const value_type* operator-> () const);
604 InputIter& operator++ () {
605 assert (*this == *this); // assert *this is valid
606 assert (cur_ < ptr_->end_); // assert *this is not past the end
613 InputIter operator++ (int) {
619 const value_type *cur_; // past-the-end
623 // satisfies the requirements in 24.1.2 [lib.output.iterators]
625 struct OutputIter: ITER_BASE (std::output_iterator_tag, T, int, T*, T&)
627 typedef T value_type;
628 typedef value_type* pointer;
629 typedef value_type& reference;
630 typedef int difference_type;
631 typedef std::output_iterator_tag iterator_category;
633 // body shared by all copies of the same OutputIter specialization
634 // to detect algorithms that pass through the same interator more
635 // than once (disallowed by 24.1.2, p2)
639 const value_type *begin_;
640 const value_type *end_;
643 Shared (pointer cur, const value_type *end)
644 : cur_ (cur), assign_ (cur), begin_ (cur), end_ (end), ref_ (1) { }
647 begin_ = end_ = cur_ = assign_ = 0;
652 Shared (const Shared&); // not defined
653 void operator= (const Shared&); // not defined
657 // class whose objects are returned from OutputIter::operator*
658 // to detect multiple assignments (disallowed by 24.1.2, p2)
660 friend struct OutputIter;
664 Proxy (Shared *ptr): ptr_ (ptr) { }
667 void operator= (const value_type &rhs) {
670 // verify that the iterator is in the valid range
671 assert (ptr_->cur_ >= ptr_->begin_ && ptr_->cur_ <= ptr_->end_);
673 // verify that the assignment point is the same as the current
674 // position `cur' within the sequence or immediately before it
675 // (in order to allow the expression: *it++ = val)
676 assert ( ptr_->assign_ == ptr_->cur_
677 || ptr_->assign_ + 1 == ptr_->cur_);
679 // assign and increment the assignment point
680 *ptr_->assign_++ = rhs;
684 // OutputIterators are not default constructible
685 OutputIter (pointer cur,
687 const value_type *end)
688 : ptr_ (new Shared (cur, end)), cur_ (cur) { }
690 OutputIter (const OutputIter &rhs)
691 : ptr_ (rhs.ptr_), cur_ (rhs.cur_) {
692 ++ptr_->ref_; // increment the reference count
696 if (0 == --ptr_->ref_) // decrement the reference count
702 OutputIter& operator= (const OutputIter &rhs) {
703 if (0 == --ptr_->ref_)
714 void operator= (const value_type &rhs) const {
718 // return a proxy in order to detect multiple assignments
719 // through the iterator (disallowed by 24.1.2, p2))
720 Proxy operator* () const {
722 assert (ptr_->assign_ && ptr_->assign_ != ptr_->end_);
727 _RWSTD_OPERATOR_ARROW (pointer operator-> () const);
729 OutputIter& operator++ () {
730 assert (cur_ == ptr_->cur_);
731 assert (ptr_->cur_ >= ptr_->begin_ && ptr_->cur_ < ptr_->end_);
736 // returning a const value rather than a modifiable value
737 // in order to verify the requirement in row 5 of Table 73
738 const OutputIter operator++ (int) {
739 OutputIter tmp (*this);
749 // satisfies the requirements in 24.1.3 [lib.forward.iterators]
751 struct FwdIter: ITER_BASE (std::forward_iterator_tag, T, int, T*, T&)
753 typedef T value_type;
754 typedef value_type* pointer;
755 typedef value_type& reference;
756 typedef int difference_type;
757 typedef std::forward_iterator_tag iterator_category;
759 FwdIter (): cur_ (0), end_ (0) { }
761 FwdIter (pointer cur,
763 const value_type *end)
764 : cur_ (cur), end_ (end) { }
766 FwdIter (const FwdIter &rhs)
767 : cur_ (rhs.cur_), end_ (rhs.end_) { }
773 FwdIter& operator= (const FwdIter &rhs) {
779 bool operator== (const FwdIter &rhs) const {
781 return cur_ == rhs.cur_;
784 bool operator!= (const FwdIter &rhs) const {
785 return !(*this == rhs);
788 reference operator* () const {
789 assert (cur_ != 0 && cur_ != end_);
793 _RWSTD_OPERATOR_ARROW (pointer operator-> () const);
795 FwdIter& operator++ () {
796 assert (cur_ != 0 && cur_ != end_);
797 return ++cur_, *this;
800 FwdIter operator++ (int) {
806 pointer cur_; // pointer to current element
807 const value_type *end_; // past-the-end
812 struct ConstFwdIter: FwdIter<T>
814 typedef T value_type;
815 typedef FwdIter<value_type> Base;
817 ConstFwdIter (): Base () { }
819 ConstFwdIter (const value_type *cur,
820 const value_type *begin,
821 const value_type *end)
822 : Base (_RWSTD_CONST_CAST (value_type*, cur), begin, end) { }
824 const value_type& operator* () const {
825 return Base::operator* ();
828 _RWSTD_OPERATOR_ARROW (const value_type* operator-> () const);
832 // satisfies the requirements in 24.1.4 [lib.bidirectional.iterators]
834 struct BidirIter: ITER_BASE (std::bidirectional_iterator_tag, T, int, T*, T&)
836 typedef T value_type;
837 typedef value_type* pointer;
838 typedef value_type& reference;
839 typedef int difference_type;
840 typedef std::bidirectional_iterator_tag iterator_category;
842 BidirIter (): cur_ (0), begin_ (0), end_ (0) { }
844 BidirIter (pointer cur,
845 const value_type *begin,
846 const value_type *end)
847 : cur_ (cur), begin_ (begin), end_ (end) { }
849 BidirIter (const BidirIter &rhs)
850 : cur_ (rhs.cur_), begin_ (rhs.begin_), end_ (rhs.end_) { }
853 begin_ = end_ = cur_ = 0;
856 BidirIter& operator= (const BidirIter &rhs) {
862 bool operator== (const BidirIter &rhs) const {
863 assert (cur_ != 0 && rhs.cur_ != 0);
864 return cur_ == rhs.cur_;
867 bool operator!= (const BidirIter &rhs) const {
868 return !(*this == rhs);
871 reference operator* () const {
872 assert (cur_ != 0 && cur_ != end_);
876 _RWSTD_OPERATOR_ARROW (pointer operator-> () const);
878 BidirIter& operator++ () {
879 assert (cur_ != 0 && cur_ != end_);
880 return ++cur_, *this;
883 BidirIter operator++ (int) {
884 BidirIter tmp (*this);
888 BidirIter& operator-- () {
889 assert (cur_ != 0 && cur_ != begin_);
890 return --cur_, *this;
893 BidirIter operator-- (int) {
894 BidirIter tmp (*this);
899 pointer cur_; // pointer to current element
900 const value_type *begin_; // first in range
901 const value_type *end_; // past-the-end
906 struct ConstBidirIter: BidirIter<T>
908 typedef T value_type;
909 typedef BidirIter<value_type> Base;
911 ConstBidirIter (): Base () { }
913 ConstBidirIter (const value_type *cur,
914 const value_type *begin,
915 const value_type *end)
916 : Base (_RWSTD_CONST_CAST (value_type*, cur), begin, end) { }
918 const value_type& operator* () const {
919 return Base::operator* ();
922 _RWSTD_OPERATOR_ARROW (const value_type* operator-> () const);
926 // satisfies the requirements in 24.1.5 [lib.random.access.iterators]
928 struct RandomAccessIter
929 : ITER_BASE (std::random_access_iterator_tag, T, int, T*, T&)
931 typedef T value_type;
932 typedef value_type* pointer;
933 typedef value_type& reference;
934 typedef int difference_type;
935 typedef std::random_access_iterator_tag iterator_category;
937 RandomAccessIter (): cur_ (0), begin_ (0), end_ (0) { }
939 RandomAccessIter (pointer cur,
940 const value_type *begin,
941 const value_type *end)
942 : cur_ (cur), begin_ (begin), end_ (end) { }
944 RandomAccessIter (const RandomAccessIter &rhs)
945 : cur_ (rhs.cur_), begin_ (rhs.begin_), end_ (rhs.end_) { }
947 ~RandomAccessIter () {
948 begin_ = end_ = cur_ = 0;
951 RandomAccessIter& operator= (const RandomAccessIter &rhs) {
958 reference operator* () const {
959 assert (cur_ != 0 && cur_ != end_);
963 _RWSTD_OPERATOR_ARROW (pointer operator-> () const);
965 RandomAccessIter& operator++ () {
966 assert (cur_ != 0 && cur_ != end_);
967 return ++cur_, *this;
970 RandomAccessIter operator++ (int) {
971 RandomAccessIter tmp (*this);
975 RandomAccessIter& operator-- () {
976 assert (cur_ != 0 && cur_ != begin_);
977 return --cur_, *this;
980 RandomAccessIter operator-- (int) {
981 RandomAccessIter tmp (*this);
985 RandomAccessIter& operator+= (difference_type n) {
987 && (!end_ || cur_ + n <= end_)
988 && (!begin_ || cur_ + n >= begin_));
989 return cur_ += n, *this;
991 RandomAccessIter& operator-= (difference_type n) {
995 RandomAccessIter operator+ (difference_type n) const {
996 return RandomAccessIter (*this) += n;
999 RandomAccessIter operator- (difference_type n) const {
1000 return RandomAccessIter (*this) -= n;
1003 difference_type operator- (const RandomAccessIter &rhs) const {
1004 assert (cur_ != 0 && rhs.cur_ != 0);
1005 return cur_ - rhs.cur_;
1008 bool operator== (const RandomAccessIter &rhs) const {
1009 assert (cur_ != 0 && rhs.cur_ != 0);
1010 return cur_ == rhs.cur_;
1013 bool operator!= (const RandomAccessIter &rhs) const {
1014 return !(*this == rhs);
1017 bool operator< (const RandomAccessIter &rhs) const {
1018 assert (cur_ != 0 && rhs.cur_ != 0);
1019 return cur_ < rhs.cur_;
1022 bool operator> (const RandomAccessIter &rhs) const {
1026 bool operator<= (const RandomAccessIter &rhs) const {
1027 return !(rhs < *this);
1030 bool operator>= (const RandomAccessIter &rhs) const {
1031 return !(*this < rhs);
1034 reference operator[] (difference_type inx) const {
1036 && (!end_ || cur_ + inx < end_)
1037 && !(begin_ || cur_ + inx >= begin_));
1042 pointer cur_; // pointer to current element
1043 const value_type *begin_; // first in range
1044 const value_type *end_; // past-the-end
1049 struct ConstRandomAccessIter: RandomAccessIter<T>
1051 typedef T value_type;
1052 typedef RandomAccessIter<value_type> Base;
1053 typedef typename Base::difference_type difference_type;
1055 ConstRandomAccessIter (): Base () { }
1057 ConstRandomAccessIter (const value_type *cur,
1058 const value_type *begin,
1059 const value_type *end)
1060 : Base (_RWSTD_CONST_CAST (value_type*, cur), begin, end) { }
1062 const value_type& operator* () const {
1063 return Base::operator* ();
1066 _RWSTD_OPERATOR_ARROW (const value_type* operator-> () const);
1068 const value_type& operator[] (difference_type inx) const {
1069 return Base::operator[] (inx);
1076 make_iter (T *cur, const T*, const T*, T*)
1083 copy_iter (T *ptr, const T*)
1088 // dummy function argument provided to help broken compilers (PR #29835)
1092 make_iter (const T *cur, const T *begin, const T *end, const InputIter<T>&)
1094 return InputIter<T>(cur, begin, end);
1099 copy_iter (const InputIter<T> &it, const T*)
1101 return InputIter<T>(it.cur_, it.ptr_->beg_, it.ptr_->end_);
1105 inline const char* type_name (InputIter<T>, const T*)
1106 { return "InputIterator"; }
1110 inline OutputIter<T>
1111 make_iter (T *cur, const T *begin, const T *end, const OutputIter<T>&)
1113 return OutputIter<T>(cur, begin, end);
1117 inline OutputIter<T>
1118 copy_iter (const OutputIter<T> &it, const T*)
1120 return OutputIter<T>(it.cur_, 0, it.ptr_->end);
1124 inline const char* type_name (OutputIter<T>, const T*)
1125 { return "OutputIterator"; }
1130 make_iter (T *cur, const T *begin, const T *end, FwdIter<T>)
1132 return FwdIter<T>(cur, begin, end);
1137 copy_iter (const FwdIter<T> &it, const T*)
1139 return FwdIter<T>(it.cur_, 0, it.end_);
1143 inline const char* type_name (FwdIter<T>, const T*)
1144 { return "ForwardIterator"; }
1148 inline ConstFwdIter<T>
1149 make_iter (T *cur, const T *begin, const T *end, ConstFwdIter<T>)
1151 return ConstFwdIter<T>(cur, begin, end);
1155 inline ConstFwdIter<T>
1156 copy_iter (const ConstFwdIter<T> &it, const T*)
1158 return ConstFwdIter<T>(it.cur_, 0, it.end_);
1162 inline const char* type_name (ConstFwdIter<T>, const T*)
1163 { return "ConstForwardIterator"; }
1168 make_iter (T *cur, const T *begin, const T *end, BidirIter<T>)
1170 return BidirIter<T>(cur, begin, end);
1175 copy_iter (const BidirIter<T> &it, const T*)
1177 return BidirIter<T>(it.cur_, it.begin_, it.end_);
1181 inline const char* type_name (BidirIter<T>, const T*)
1182 { return "BidirectionalIterator"; }
1186 inline ConstBidirIter<T>
1187 make_iter (T *cur, const T *begin, const T *end, ConstBidirIter<T>)
1189 return ConstBidirIter<T>(cur, begin, end);
1193 inline ConstBidirIter<T>
1194 copy_iter (const ConstBidirIter<T> &it, const T*)
1196 return ConstBidirIter<T>(it.cur_, it.begin_, it.end_);
1200 inline const char* type_name (ConstBidirIter<T>, const T*)
1201 { return "ConstBidirectionalIterator"; }
1205 inline RandomAccessIter<T>
1206 make_iter (T *cur, const T *begin, const T *end, RandomAccessIter<T>)
1208 return RandomAccessIter<T>(cur, begin, end);
1212 inline RandomAccessIter<T>
1213 copy_iter (const RandomAccessIter<T> &it, const T*)
1215 return RandomAccessIter<T>(it.cur_, it.begin_, it.end_);
1219 inline const char* type_name (RandomAccessIter<T>, const T*)
1220 { return "RandomAccessIterator"; }
1224 inline ConstRandomAccessIter<T>
1225 make_iter (T *cur, const T *begin, const T *end, ConstRandomAccessIter<T>)
1227 return ConstRandomAccessIter<T>(cur, begin, end);
1231 inline ConstRandomAccessIter<T>
1232 copy_iter (const ConstRandomAccessIter<T> &it, const T*)
1234 return ConstRandomAccessIter<T>(it.cur_, it.begin_, it.end_);
1238 inline const char* type_name (ConstRandomAccessIter<T>, const T*)
1239 { return "ConstRandomAccessIterator"; }
1241 typedef int (*fptr_gen_)();
1243 //exporting fun for exporting global var
1244 _TEST_EXPORT _RWSTD_SIZE_T* Getn_total_op_assign_();
1245 _TEST_EXPORT _RWSTD_SIZE_T* Getn_total_op_eq_();
1246 _TEST_EXPORT fptr_gen_* Get_gen_();
1247 #endif // _RWSTD_ALG_TEST_H_INCLUDED