]> git.tdb.fi Git - gldbg.git/blob - source/autoconstptr.h
Replace per-file license notices with License.txt
[gldbg.git] / source / autoconstptr.h
1 #ifndef AUTOCONSTPTR_H_
2 #define AUTOCONSTPTR_H_
3
4 /**
5 A smart pointer that only provides non-const access to the contents if the
6 pointer itself is non-const.
7 */
8 template<typename T>
9 class AutoConstPtr
10 {
11 private:
12         T *ptr;
13
14 public:
15         AutoConstPtr(T *p): ptr(p) { }
16         AutoConstPtr &operator=(T *p) { ptr = p; return *this; }
17         T *operator->() { return ptr; }
18         const T *operator->() const { return ptr; }
19         operator T *() { return ptr; }
20         operator const T *() const { return ptr; }
21 };
22
23 #endif