]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/vector.h
in release builds gcc on osx evaporates these inlines if not WXEXPORTed
[wxWidgets.git] / include / wx / vector.h
index df491781a048997376e258f80019d595d8eaebed..d77962d7783d781c0f65ae9dbc7498af09270ccf 100644 (file)
@@ -117,11 +117,55 @@ private:
 
 public:
     typedef size_t size_type;
+    typedef size_t difference_type;
     typedef T value_type;
+    typedef value_type* pointer;
     typedef value_type* iterator;
     typedef const value_type* const_iterator;
     typedef value_type& reference;
 
+    class reverse_iterator
+    {
+    public:
+        reverse_iterator() : m_ptr(NULL) { }
+        wxEXPLICIT reverse_iterator(iterator it) : m_ptr(it) { }
+        reverse_iterator(const reverse_iterator& it) : m_ptr(it.m_ptr) { }
+        
+        reference operator*() const { return *m_ptr; }
+        pointer operator->() const { return m_ptr; }
+        
+        iterator base() const { return m_ptr; }
+        
+        reverse_iterator& operator++() 
+                { --m_ptr; return *this; }
+        reverse_iterator operator++(int)
+                { reverse_iterator tmp = *this; --m_ptr; return tmp; }
+        reverse_iterator& operator--() 
+                { ++m_ptr; return *this; }
+        reverse_iterator operator--(int) 
+                { reverse_iterator tmp = *this; ++m_ptr; return tmp; }
+        
+        reverse_iterator operator+(difference_type n) const
+                { return reverse_iterator(m_ptr - n); }
+        reverse_iterator& operator+=(difference_type n)
+                { return m_ptr -= n; return *this; }
+        reverse_iterator operator-(difference_type n) const
+                { return reverse_iterator(m_ptr + n); }
+        reverse_iterator& operator-=(difference_type n)
+                { return m_ptr += n; return *this; }
+                
+        reference operator[](difference_type n) const
+                { return *(*this + n); }
+        
+        bool operator ==(const reverse_iterator& it) const 
+                { return m_ptr == it.m_ptr; }
+        bool operator !=(const reverse_iterator& it) const
+                { return m_ptr != it.m_ptr; }
+        
+    private:
+        value_type *m_ptr;
+    };
+
     wxVector() : m_size(0), m_capacity(0), m_values(NULL) {}
 
     wxVector(const wxVector& c) : m_size(0), m_capacity(0), m_values(NULL)
@@ -235,6 +279,9 @@ public:
     const_iterator end() const { return m_values + size(); }
     iterator end() { return m_values + size(); }
 
+    reverse_iterator rbegin() { return reverse_iterator(end() - 1); }
+    reverse_iterator rend() { return reverse_iterator(begin() - 1); }
+
     iterator insert(iterator it, const value_type& v = value_type())
     {
         // NB: this must be done before reserve(), because reserve()