]> git.saurik.com Git - wxWidgets.git/commitdiff
only provide ptrdiff_t versions of verious operator+/- working with iterators instead...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 6 Jan 2008 22:27:01 +0000 (22:27 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 6 Jan 2008 22:27:01 +0000 (22:27 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51053 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/string.h
include/wx/stringimpl.h
include/wx/stringops.h

index aef07e6885a494d3e6ab6096250aec92dcdae3e3..6ab3eda765f464d86c31d2fda3c05a5a395b8fa3 100644 (file)
@@ -237,22 +237,12 @@ public:
     wxCStrData operator+(size_t n) const
         { return wxCStrData(m_str, m_offset + n, m_owned); }
 
-    // and these for "str.c_str() + n - 2":
-    wxCStrData operator-(int n) const
+    // and these for "str.c_str() + (p2 - p1)" (it also works for any integer
+    // expression but it must be ptrdiff_t and not e.g. int to work in this
+    // example):
+    wxCStrData operator-(ptrdiff_t n) const
     {
-        wxASSERT_MSG( n <= (int)m_offset,
-                      _T("attempt to construct address before the beginning of the string") );
-        return wxCStrData(m_str, m_offset - n, m_owned);
-    }
-    wxCStrData operator-(long n) const
-    {
-        wxASSERT_MSG( n <= (int)m_offset,
-                      _T("attempt to construct address before the beginning of the string") );
-        return wxCStrData(m_str, m_offset - n, m_owned);
-    }
-    wxCStrData operator-(size_t n) const
-    {
-        wxASSERT_MSG( n <= m_offset,
+        wxASSERT_MSG( n <= (ptrdiff_t)m_offset,
                       _T("attempt to construct address before the beginning of the string") );
         return wxCStrData(m_str, m_offset - n, m_owned);
     }
@@ -603,25 +593,15 @@ public:
               return tmp;                                                   \
           }                                                                 \
                                                                             \
-          iterator_name& operator+=(int n)                                  \
+          iterator_name& operator+=(ptrdiff_t n)                            \
           {                                                                 \
               m_cur = wxStringOperations::AddToIter(m_cur, n);              \
               return *this;                                                 \
           }                                                                 \
-          iterator_name& operator+=(size_t n)                               \
-          {                                                                 \
-              m_cur = wxStringOperations::AddToIter(m_cur, (int)n);         \
-              return *this;                                                 \
-          }                                                                 \
-          iterator_name& operator-=(int n)                                  \
+          iterator_name& operator-=(ptrdiff_t n)                            \
           {                                                                 \
               m_cur = wxStringOperations::AddToIter(m_cur, -n);             \
               return *this;                                                 \
-          }                                                                 \
-          iterator_name& operator-=(size_t n)                               \
-          {                                                                 \
-              m_cur = wxStringOperations::AddToIter(m_cur, -(int)n);        \
-              return *this;                                                 \
           }                                                                 \
                                                                             \
           difference_type operator-(const iterator_name& i) const           \
@@ -682,14 +662,10 @@ public:
       reference operator*()
         { return wxUniCharRef::CreateForString(m_node, m_cur); }
 
-      iterator operator+(int n) const
+      iterator operator+(ptrdiff_t n) const
         { return iterator(str(), wxStringOperations::AddToIter(m_cur, n)); }
-      iterator operator+(size_t n) const
-        { return iterator(str(), wxStringOperations::AddToIter(m_cur, (int)n)); }
-      iterator operator-(int n) const
+      iterator operator-(ptrdiff_t n) const
         { return iterator(str(), wxStringOperations::AddToIter(m_cur, -n)); }
-      iterator operator-(size_t n) const
-        { return iterator(str(), wxStringOperations::AddToIter(m_cur, -(int)n)); }
 
   private:
       iterator(wxString *str, underlying_iterator ptr)
@@ -723,14 +699,10 @@ public:
       reference operator*() const
         { return wxStringOperations::DecodeChar(m_cur); }
 
-      const_iterator operator+(int n) const
+      const_iterator operator+(ptrdiff_t n) const
         { return const_iterator(str(), wxStringOperations::AddToIter(m_cur, n)); }
-      const_iterator operator+(size_t n) const
-        { return const_iterator(str(), wxStringOperations::AddToIter(m_cur, (int)n)); }
-      const_iterator operator-(int n) const
+      const_iterator operator-(ptrdiff_t n) const
         { return const_iterator(str(), wxStringOperations::AddToIter(m_cur, -n)); }
-      const_iterator operator-(size_t n) const
-        { return const_iterator(str(), wxStringOperations::AddToIter(m_cur, -(int)n)); }
 
   private:
       // for internal wxString use only:
@@ -758,14 +730,10 @@ public:
       reference operator*()
         { return wxUniCharRef::CreateForString(m_cur); }
 
-      iterator operator+(int n) const
+      iterator operator+(ptrdiff_t n) const
         { return iterator(wxStringOperations::AddToIter(m_cur, n)); }
-      iterator operator+(size_t n) const
-        { return iterator(wxStringOperations::AddToIter(m_cur, (int)n)); }
-      iterator operator-(int n) const
+      iterator operator-(ptrdiff_t n) const
         { return iterator(wxStringOperations::AddToIter(m_cur, -n)); }
-      iterator operator-(size_t n) const
-        { return iterator(wxStringOperations::AddToIter(m_cur, -(int)n)); }
 
   private:
       // for internal wxString use only:
@@ -789,14 +757,10 @@ public:
       reference operator*() const
         { return wxStringOperations::DecodeChar(m_cur); }
 
-      const_iterator operator+(int n) const
+      const_iterator operator+(ptrdiff_t n) const
         { return const_iterator(wxStringOperations::AddToIter(m_cur, n)); }
-      const_iterator operator+(size_t n) const
-        { return const_iterator(wxStringOperations::AddToIter(m_cur, (int)n)); }
-      const_iterator operator-(int n) const
+      const_iterator operator-(ptrdiff_t n) const
         { return const_iterator(wxStringOperations::AddToIter(m_cur, -n)); }
-      const_iterator operator-(size_t n) const
-        { return const_iterator(wxStringOperations::AddToIter(m_cur, -(int)n)); }
 
   private:
       // for internal wxString use only:
@@ -844,21 +808,13 @@ public:
         { reverse_iterator_impl tmp = *this; ++m_cur; return tmp; }
 
       // NB: explicit <T> in the functions below is to keep BCC 5.5 happy
-      reverse_iterator_impl operator+(int n) const
+      reverse_iterator_impl operator+(ptrdiff_t n) const
         { return reverse_iterator_impl<T>(m_cur - n); }
-      reverse_iterator_impl operator+(size_t n) const
-        { return reverse_iterator_impl<T>(m_cur - n); }
-      reverse_iterator_impl operator-(int n) const
-        { return reverse_iterator_impl<T>(m_cur + n); }
-      reverse_iterator_impl operator-(size_t n) const
+      reverse_iterator_impl operator-(ptrdiff_t n) const
         { return reverse_iterator_impl<T>(m_cur + n); }
-      reverse_iterator_impl operator+=(int n)
-        { m_cur -= n; return *this; }
-      reverse_iterator_impl operator+=(size_t n)
+      reverse_iterator_impl operator+=(ptrdiff_t n)
         { m_cur -= n; return *this; }
-      reverse_iterator_impl operator-=(int n)
-        { m_cur += n; return *this; }
-      reverse_iterator_impl operator-=(size_t n)
+      reverse_iterator_impl operator-=(ptrdiff_t n)
         { m_cur += n; return *this; }
 
       unsigned operator-(const reverse_iterator_impl& i) const
@@ -2637,21 +2593,13 @@ private:
 
 // string iterator operators that satisfy STL Random Access Iterator
 // requirements:
-inline wxString::iterator operator+(int n, wxString::iterator i)
-  { return i + n; }
-inline wxString::iterator operator+(size_t n, wxString::iterator i)
-  { return i + n; }
-inline wxString::const_iterator operator+(int n, wxString::const_iterator i)
-  { return i + n; }
-inline wxString::const_iterator operator+(size_t n, wxString::const_iterator i)
-  { return i + n; }
-inline wxString::reverse_iterator operator+(int n, wxString::reverse_iterator i)
+inline wxString::iterator operator+(ptrdiff_t n, wxString::iterator i)
   { return i + n; }
-inline wxString::reverse_iterator operator+(size_t n, wxString::reverse_iterator i)
+inline wxString::const_iterator operator+(ptrdiff_t n, wxString::const_iterator i)
   { return i + n; }
-inline wxString::const_reverse_iterator operator+(int n, wxString::const_reverse_iterator i)
+inline wxString::reverse_iterator operator+(ptrdiff_t n, wxString::reverse_iterator i)
   { return i + n; }
-inline wxString::const_reverse_iterator operator+(size_t n, wxString::const_reverse_iterator i)
+inline wxString::const_reverse_iterator operator+(ptrdiff_t n, wxString::const_reverse_iterator i)
   { return i + n; }
 
 // notice that even though for many compilers the friend declarations above are
index 7ac70a6c5e453f954114868d93a02987b906874c..54b7af59199a96478c228c4e8d843e7e6e68e63a 100644 (file)
@@ -219,21 +219,13 @@ public:
             return tmp;                                                       \
         }                                                                     \
                                                                               \
-        iterator_name operator+(int n) const                                  \
+        iterator_name operator+(ptrdiff_t n) const                            \
             { return iterator_name(m_ptr + n); }                              \
-        iterator_name operator+(size_t n) const                               \
-            { return iterator_name(m_ptr + n); }                              \
-        iterator_name operator-(int n) const                                  \
-            { return iterator_name(m_ptr - n); }                              \
-        iterator_name operator-(size_t n) const                               \
+        iterator_name operator-(ptrdiff_t n) const                            \
             { return iterator_name(m_ptr - n); }                              \
-        iterator_name& operator+=(int n)                                      \
+        iterator_name& operator+=(ptrdiff_t n)                                \
             { m_ptr += n; return *this; }                                     \
-        iterator_name& operator+=(size_t n)                                   \
-            { m_ptr += n; return *this; }                                     \
-        iterator_name& operator-=(int n)                                      \
-            { m_ptr -= n; return *this; }                                     \
-        iterator_name& operator-=(size_t n)                                   \
+        iterator_name& operator-=(ptrdiff_t n)                                \
             { m_ptr -= n; return *this; }                                     \
                                                                               \
         difference_type operator-(const iterator_name& i) const               \
index 2e36900adc7ecb90908c2c1ce709857ff1a7fcea..50aa1376ac30215f5c204395122c5b1d440e0416 100644 (file)
@@ -36,17 +36,17 @@ struct WXDLLIMPEXP_BASE wxStringOperationsWchar
     static void DecIter(wxStringImpl::const_iterator& i) { --i; }
 
     // moves the iterator by n Unicode characters
-    static wxStringImpl::iterator AddToIter(const wxStringImpl::iterator& i, int n)
+    static wxStringImpl::iterator AddToIter(const wxStringImpl::iterator& i, ptrdiff_t n)
         { return i + n; }
-    static wxStringImpl::const_iterator AddToIter(const wxStringImpl::const_iterator& i, int n)
+    static wxStringImpl::const_iterator AddToIter(const wxStringImpl::const_iterator& i, ptrdiff_t n)
         { return i + n; }
 
     // returns distance of the two iterators in Unicode characters
-    static int DiffIters(const wxStringImpl::iterator& i1,
-                         const wxStringImpl::iterator& i2)
+    static ptrdiff_t DiffIters(const wxStringImpl::iterator& i1,
+                               const wxStringImpl::iterator& i2)
         { return i1 - i2; }
-    static int DiffIters(const wxStringImpl::const_iterator& i1,
-                         const wxStringImpl::const_iterator& i2)
+    static ptrdiff_t DiffIters(const wxStringImpl::const_iterator& i1,
+                               const wxStringImpl::const_iterator& i2)
         { return i1 - i2; }
 
     // encodes the character to a form used to represent it in internal
@@ -97,18 +97,18 @@ struct WXDLLIMPEXP_BASE wxStringOperationsUtf8
     }
 
     template<typename Iterator>
-    static Iterator AddToIter(const Iterator& i, int n)
+    static Iterator AddToIter(const Iterator& i, ptrdiff_t n)
     {
         Iterator out(i);
 
         if ( n > 0 )
         {
-            for ( int j = 0; j < n; ++j )
+            for ( ptrdiff_t j = 0; j < n; ++j )
                 IncIter(out);
         }
         else if ( n < 0 )
         {
-            for ( int j = 0; j > n; --j )
+            for ( ptrdiff_t j = 0; j > n; --j )
                 DecIter(out);
         }
 
@@ -116,9 +116,9 @@ struct WXDLLIMPEXP_BASE wxStringOperationsUtf8
     }
 
     template<typename Iterator>
-    static int DiffIters(Iterator i1, Iterator i2)
+    static ptrdiff_t DiffIters(Iterator i1, Iterator i2)
     {
-        int dist = 0;
+        ptrdiff_t dist = 0;
 
         if ( i1 < i2 )
         {