ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtvec.h
Revision: 1.2
Committed: Mon Nov 24 19:52:16 2003 UTC (20 years, 6 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +43 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #ifndef RXVT_VEC_H
2 #define RXVT_VEC_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 <cstring>
8 #include "simplevec.h"
9
10 #if 0
11 template<typename T>
12 struct rxvt_vec : simplevec<void *> {
13 typedef T *iterator;
14
15 void push_back (T d) { simplevec<void *>::push_back ((void *)d); }
16 T pop_back () { return (T*)simplevec<void *>::pop_back (); }
17 void erase (int i) { erase (begin () + i); }
18 void erase (iterator i) { simplevec<void *>::erase ((void **)i); }
19 iterator begin () const { return (iterator)simplevec<void *>::begin (); }
20 iterator end () const { return (iterator)simplevec<void *>::end (); }
21 T &operator [](int i) { return *(T *)(&((*(simplevec<void *> *)this)[i])); }
22 const T &operator [](int i) const { return *(const T *)(&((*(const simplevec<void *> *)this)[i])); }
23 };
24 #endif
25
26 template <typename I, typename T>
27 I find(I first, I last, const T& value)
28 {
29 while (first != last && *first != value)
30 ++first;
31
32 return first;
33 }
34
35 template<typename T>
36 struct auto_ptr {
37 T *p;
38
39 auto_ptr() : p(0) { }
40 auto_ptr(T *a) : p(a) { }
41
42 template<typename A>
43 auto_ptr(auto_ptr<A> &a)
44 {
45 p = a.p;
46 a.p = 0;
47 }
48
49 // void because it makes sense in our context
50 void operator =(T *a)
51 {
52 delete p;
53 p = a;
54 }
55
56 template<typename A>
57 void operator =(auto_ptr<A> &a)
58 {
59 *this = a.p;
60 a.p = 0;
61 }
62
63 operator T *() const { return p; }
64
65 T *operator ->() const { return p; }
66 T &operator *() const { return *p; }
67
68 T *get ()
69 {
70 T *r = p;
71 p = 0;
72 return r;
73 }
74 };
75
76 typedef auto_ptr<char> auto_str;
77
78 #endif