00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef SGI_misc_extension_h_INCLUDED
00042 #define SGI_misc_extension_h_INCLUDED
00043
00044 #include <iterator>
00045
00046 namespace SGI {
00047
00048 using std::random_access_iterator_tag;
00049
00050 template <class T1, class T2, class T3>
00051 struct triple {
00052 typedef T1 first_type;
00053 typedef T2 second_type;
00054 typedef T3 third_type;
00055
00056 T1 first;
00057 T2 second;
00058 T3 third;
00059 triple() : first(T1()), second(T2()), third(T3()) {}
00060 triple(const T1& a, const T2& b, const T3& c) : first(a), second(b), third(c) {}
00061
00062 template <class U1, class U2, class U3>
00063 triple(const triple<U1, U2, U3>& p) : first(p.first), second(p.second), third(p.third) {}
00064 };
00065
00066 template<class T1, class T2, class T3>
00067 inline triple<T1, T2, T3>
00068 make_triple(const T1& x1, const T2& x2, const T3& x3) {
00069 return triple<T1, T2, T3>(x1, x2, x3);
00070 }
00071
00072 template <class T1, class T2, class T3, class T4>
00073 struct quadruple {
00074 typedef T1 first_type;
00075 typedef T2 second_type;
00076 typedef T3 third_type;
00077 typedef T4 fourth_type;
00078
00079 T1 first;
00080 T2 second;
00081 T3 third;
00082 T4 fourth;
00083 quadruple() : first(T1()), second(T2()), third(T3()), fourth(T4()) {}
00084 quadruple(const T1& a, const T2& b, const T3& c, const T4& d) :
00085 first(a), second(b), third(c), fourth(d) {}
00086
00087 template <class U1, class U2, class U3, class U4>
00088 quadruple(const quadruple<U1, U2, U3, U4>& p) :
00089 first(p.first), second(p.second), third(p.third), fourth(p.fourth) {}
00090 };
00091
00092 template<class T1, class T2, class T3, class T4>
00093 inline quadruple<T1, T2, T3, T4>
00094 make_quadruple(const T1& x1, const T2& x2, const T3& x3, const T4& x4) {
00095 return quadruple<T1, T2, T3, T4>(x1, x2, x3, x4);
00096 }
00097
00098 template <class Tuple>
00099 inline typename Tuple::first_type first(Tuple t) {
00100 return t.first;
00101 }
00102
00103 template <class Tuple>
00104 inline typename Tuple::second_type second(Tuple t) {
00105 return t.second;
00106 }
00107
00108 template <class Tuple>
00109 inline typename Tuple::third_type third(Tuple t) {
00110 return t.third;
00111 }
00112
00113 template <class Tuple>
00114 inline typename Tuple::fourth_type fourth(Tuple t) {
00115 return t.fourth;
00116 }
00117
00118
00119 template <class Integer>
00120 struct int_iterator {
00121 protected:
00122 Integer base;
00123 public:
00124 typedef int_iterator<Integer> self;
00125 typedef random_access_iterator_tag iterator_category;
00126 typedef Integer value_type;
00127 typedef Integer difference_type;
00128 typedef Integer* pointer;
00129 typedef Integer& reference;
00130
00131 self operator ++(int) { self tmp = *this; ++base; return tmp; }
00132 self &operator ++() { ++base; return *this; }
00133 self operator --(int) { self tmp = *this; --base; return tmp; }
00134 self &operator --() { --base; return *this; }
00135 self &operator +=(int n) { base += n; return *this; }
00136 self &operator -=(int n) { base -= n; return *this; }
00137 difference_type operator-(const self& x) const { return base - x.base; }
00138 self operator+(difference_type n) const { return self(base + n); }
00139 self operator-(difference_type n) const { return self(base - n); }
00140
00141 Integer operator*() const { return base; }
00142 Integer operator[](int n) const { return *(*this + n); }
00143
00144 int_iterator(Integer i):base(i){}
00145 int_iterator():base(){}
00146 };
00147
00148 template <class Integer>
00149 inline bool operator==(int_iterator<Integer> x, int_iterator<Integer> y) {
00150 return *x == *y;
00151 }
00152
00153 template <class Integer>
00154 inline bool operator!=(int_iterator<Integer> x, int_iterator<Integer> y) {
00155 return *x != *y;
00156 }
00157
00158 template <class Integer>
00159 inline bool operator<(int_iterator<Integer> x, int_iterator<Integer> y) {
00160 return *x < *y;
00161 }
00162
00163 template<class Integer>
00164 inline int_iterator<Integer>
00165 operator+(Integer x, const int_iterator<Integer>& y) {
00166 return y + x;
00167 }
00168
00169 #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
00170
00171 template <class Integer>
00172 inline bool
00173 operator!=(const int_iterator<Integer>& x, const int_iterator<Integer>& y) {
00174 return !(x == y);
00175 }
00176
00177 template <class Integer>
00178 inline bool
00179 operator>(const int_iterator<Integer>& x, const int_iterator<Integer>& y) {
00180 return y < x;
00181 }
00182
00183 template <class Integer>
00184 inline bool
00185 operator<=(const int_iterator<Integer>& x, const int_iterator<Integer>& y) {
00186 return !(y < x);
00187 }
00188
00189 template <class Integer>
00190 inline bool
00191 operator>=(const int_iterator<Integer>& x, const int_iterator<Integer>& y) {
00192 return !(x < y);
00193 }
00194
00195 #endif
00196
00197
00198 struct output_iterator {
00199 typedef std::output_iterator_tag iterator_category;
00200 typedef void value_type;
00201 typedef void difference_type;
00202 typedef void pointer;
00203 typedef void reference;
00204 };
00205
00206 template <class Container>
00207 class push_iterator : public output_iterator {
00208 protected:
00209 Container& container;
00210 public:
00211 push_iterator(Container& x) : container(x) {}
00212 push_iterator<Container>&
00213 operator=(const typename Container::value_type& value) {
00214 container.push(value);
00215 return *this;
00216 }
00217 push_iterator<Container>& operator*() { return *this; }
00218 push_iterator<Container>& operator++() { return *this; }
00219 push_iterator<Container>& operator++(int) { return *this; }
00220 };
00221
00222
00223 template <class Indexable, class IndexFunction>
00224 class index_iterator : public output_iterator {
00225 protected:
00226 typedef index_iterator<Indexable, IndexFunction> self;
00227 Indexable& p;
00228 IndexFunction i_fun;
00229 public:
00230 index_iterator(Indexable& x, const IndexFunction& f) : p(x), i_fun(f) {}
00231 template <class T>
00232 self& operator=(const T& value) {
00233 p[i_fun(value)] = value;
00234 return *this;
00235 }
00236 self& operator*() { return *this; }
00237 self& operator++() { return *this; }
00238 self& operator++(int) { return *this; }
00239 };
00240
00241
00242 template <class From, class To>
00243 struct converter : public std::unary_function<From, To> {
00244 To operator()(const From& x) { return To(x); }
00245 };
00246
00247
00248
00249
00250
00251
00252 }
00253
00254 #endif
00255
00256
00257
00258