--- /dev/null
+/* $Id$
+
+This file is part of gldbg
+Copyright © 2009 Mikko Rasa, Mikkosoft Productions
+Distributed under the GPL
+*/
+
+#ifndef AUTOCONSTPTR_H_
+#define AUTOCONSTPTR_H_
+
+/**
+A smart pointer that only provides non-const access to the contents if the
+pointer itself is non-const.
+*/
+template<typename T>
+class AutoConstPtr
+{
+private:
+ T *ptr;
+
+public:
+ AutoConstPtr(T *p): ptr(p) { }
+ AutoConstPtr &operator=(T *p) { ptr = p; return *this; }
+ T *operator->() { return ptr; }
+ const T *operator->() const { return ptr; }
+ operator T *() { return ptr; }
+ operator const T *() const { return ptr; }
+};
+
+#endif