ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtstl.h
Revision: 1.1
Committed: Sat Jan 17 01:20:01 2004 UTC (20 years, 4 months ago) by pcg
Content type: text/plain
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# Content
1 #ifndef RXVT_STL_H
2 #define RXVT_STL_H
3
4 template<typename T> static inline T min (T a, long b) { return a < b ? a : b; }
5 template<typename T> static inline T max (T a, long b) { return a > b ? a : b; }
6
7 #include "simplevec.h"
8
9 template<typename T>
10 struct vector : simplevec<T>
11 {
12 };
13
14 #if 0
15 template<typename T>
16 struct rxvt_vec : simplevec<void *> {
17 typedef T *iterator;
18
19 void push_back (T d) { simplevec<void *>::push_back ((void *)d); }
20 T pop_back () { return (T*)simplevec<void *>::pop_back (); }
21 void erase (int i) { erase (begin () + i); }
22 void erase (iterator i) { simplevec<void *>::erase ((void **)i); }
23 iterator begin () const { return (iterator)simplevec<void *>::begin (); }
24 iterator end () const { return (iterator)simplevec<void *>::end (); }
25 T &operator [](int i) { return *(T *)(&((*(simplevec<void *> *)this)[i])); }
26 const T &operator [](int i) const { return *(const T *)(&((*(const simplevec<void *> *)this)[i])); }
27 };
28 #endif
29
30 template <typename I, typename T>
31 I find(I first, I last, const T& value)
32 {
33 while (first != last && *first != value)
34 ++first;
35
36 return first;
37 }
38
39 template<typename T>
40 struct auto_ptr {
41 T *p;
42
43 auto_ptr() : p(0) { }
44 auto_ptr(T *a) : p(a) { }
45
46 auto_ptr(auto_ptr<T> &a)
47 {
48 p = a.p;
49 a.p = 0;
50 }
51
52 template<typename A>
53 auto_ptr(auto_ptr<A> &a)
54 {
55 p = a.p;
56 a.p = 0;
57 }
58
59 ~auto_ptr()
60 {
61 delete p;
62 }
63
64 // void because it makes sense in our context
65 void operator =(T *a)
66 {
67 delete p;
68 p = a;
69 }
70
71 void operator =(auto_ptr &a)
72 {
73 *this = a.p;
74 a.p = 0;
75 }
76
77 template<typename A>
78 void operator =(auto_ptr<A> &a)
79 {
80 *this = a.p;
81 a.p = 0;
82 }
83
84 operator T *() const { return p; }
85
86 T *operator ->() const { return p; }
87 T &operator *() const { return *p; }
88
89 T *get ()
90 {
91 T *r = p;
92 p = 0;
93 return r;
94 }
95 };
96
97 typedef auto_ptr<char> auto_str;
98
99 struct stringvec : simplevec<char *>
100 {
101 ~stringvec ()
102 {
103 for (char **c = begin(); c != end(); c++)
104 delete [] *c;
105 }
106 };
107
108 #endif
109