ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtstl.h
Revision: 1.3
Committed: Mon Feb 9 07:11:49 2004 UTC (20 years, 3 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.2: +1 -2 lines
Log Message:
*** empty log message ***

File Contents

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