From d4e73d4db7538331ddb51172117d580d488982b9 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 21 Feb 2002 00:32:24 +0000 Subject: [PATCH] use more reliable non-const typecast --- panda/src/putil/ordered_vector.I | 24 +++++++++++++++++++----- panda/src/putil/ordered_vector.h | 1 + 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/panda/src/putil/ordered_vector.I b/panda/src/putil/ordered_vector.I index ae95a7422c..e2146b4a9f 100644 --- a/panda/src/putil/ordered_vector.I +++ b/panda/src/putil/ordered_vector.I @@ -358,7 +358,7 @@ clear() { template INLINE ordered_vector::iterator ordered_vector:: find(const ordered_vector::key_type &key) { - return (iterator)r_find(begin(), end(), end(), key); + return nci(r_find(begin(), end(), end(), key)); } //////////////////////////////////////////////////////////////////// @@ -394,7 +394,7 @@ find(const ordered_vector::key_type &key) const { template INLINE ordered_vector::iterator ordered_vector:: find_particular(const ordered_vector::key_type &key) { - return (iterator)r_find_particular(begin(), end(), end(), key); + return nci(r_find_particular(begin(), end(), end(), key)); } //////////////////////////////////////////////////////////////////// @@ -437,7 +437,7 @@ count(const key_type &key) const { template INLINE ordered_vector::iterator ordered_vector:: lower_bound(const ordered_vector::key_type &key) { - return (iterator)r_lower_bound(begin(), end(), key); + return nci(r_lower_bound(begin(), end(), key)); } //////////////////////////////////////////////////////////////////// @@ -462,7 +462,7 @@ lower_bound(const ordered_vector::key_type &key) const { template INLINE ordered_vector::iterator ordered_vector:: upper_bound(const ordered_vector::key_type &key) { - return (iterator)r_upper_bound(begin(), end(), key); + return nci(r_upper_bound(begin(), end(), key)); } //////////////////////////////////////////////////////////////////// @@ -488,7 +488,7 @@ INLINE pair::iterator, ordered_vector equal_range(const ordered_vector::key_type &key) { pair::const_iterator, ordered_vector::const_iterator> result; result = r_equal_range(begin(), end(), key); - return pair::iterator, ordered_vector::iterator>((iterator)result.first, (iterator)result.second); + return pair::iterator, ordered_vector::iterator>(nci(result.first), nci(result.second)); } //////////////////////////////////////////////////////////////////// @@ -541,6 +541,20 @@ sort() { ::sort(begin(), end(), _compare); } +//////////////////////////////////////////////////////////////////// +// Function: ordered_vector::nci +// Access: Private +// Description: I.e. "non-const iterator". This function is used to +// typecast a const iterator to a non-const iterator for +// easy definition of const vs. non-const flavors of +// some of these methods. +//////////////////////////////////////////////////////////////////// +template +INLINE ordered_vector::iterator ordered_vector:: +nci(ordered_vector::const_iterator iterator) { + return begin() + (iterator - begin()); +} + //////////////////////////////////////////////////////////////////// // Function: ordered_vector::find_insert_position // Access: Private diff --git a/panda/src/putil/ordered_vector.h b/panda/src/putil/ordered_vector.h index ed895b7aa9..ace4a7f4bb 100644 --- a/panda/src/putil/ordered_vector.h +++ b/panda/src/putil/ordered_vector.h @@ -125,6 +125,7 @@ public: INLINE void sort(); private: + INLINE iterator nci(const_iterator iterator); INLINE iterator find_insert_position(iterator first, iterator last, const key_type &key); iterator r_find_insert_position(iterator first, iterator last,