Boost logo

Boost-Commit :

From: daniel_james_at_[hidden]
Date: 2007-10-11 19:49:32


Author: danieljames
Date: 2007-10-11 19:49:31 EDT (Thu, 11 Oct 2007)
New Revision: 39950
URL: http://svn.boost.org/trac/boost/changeset/39950

Log:
Change insert/erase as specified in n2369, the implementation and tests.

I accidently only checked in the documentation from these changes in the
last check in. This contains the rest of it.

Text files modified:
   sandbox/unordered/boost/unordered_map.hpp | 42 +++++----------------------------------
   sandbox/unordered/boost/unordered_set.hpp | 24 +++++++++++-----------
   sandbox/unordered/libs/unordered/test/objects/minimal.hpp | 10 ++++----
   sandbox/unordered/libs/unordered/test/unordered/compile_tests.cpp | 18 ++--------------
   4 files changed, 26 insertions(+), 68 deletions(-)

Modified: sandbox/unordered/boost/unordered_map.hpp
==============================================================================
--- sandbox/unordered/boost/unordered_map.hpp (original)
+++ sandbox/unordered/boost/unordered_map.hpp 2007-10-11 19:49:31 EDT (Thu, 11 Oct 2007)
@@ -158,47 +158,32 @@
                     base.insert(obj));
         }
 
- iterator insert(iterator hint, const value_type& obj)
+ iterator insert(const_iterator hint, const value_type& obj)
         {
             return iterator(base.insert(get(hint), obj));
         }
 
- const_iterator insert(const_iterator hint, const value_type& obj)
- {
- return const_iterator(base.insert(get(hint), obj));
- }
-
         template <class InputIterator>
             void insert(InputIterator first, InputIterator last)
         {
             base.insert(first, last);
         }
 
- iterator erase(iterator position)
+ iterator erase(const_iterator position)
         {
             return iterator(base.erase(get(position)));
         }
 
- const_iterator erase(const_iterator position)
- {
- return const_iterator(base.erase(get(position)));
- }
-
         size_type erase(const key_type& k)
         {
             return base.erase(k);
         }
 
- iterator erase(iterator first, iterator last)
+ iterator erase(const_iterator first, const_iterator last)
         {
             return iterator(base.erase(get(first), get(last)));
         }
 
- const_iterator erase(const_iterator first, const_iterator last)
- {
- return const_iterator(base.erase(get(first), get(last)));
- }
-
         void clear()
         {
             base.clear();
@@ -477,47 +462,32 @@
             return iterator(base.insert(obj));
         }
 
- iterator insert(iterator hint, const value_type& obj)
+ iterator insert(const_iterator hint, const value_type& obj)
         {
             return iterator(base.insert(get(hint), obj));
         }
 
- const_iterator insert(const_iterator hint, const value_type& obj)
- {
- return const_iterator(base.insert(get(hint), obj));
- }
-
         template <class InputIterator>
             void insert(InputIterator first, InputIterator last)
         {
             base.insert(first, last);
         }
 
- iterator erase(iterator position)
+ iterator erase(const_iterator position)
         {
             return iterator(base.erase(get(position)));
         }
 
- const_iterator erase(const_iterator position)
- {
- return const_iterator(base.erase(get(position)));
- }
-
         size_type erase(const key_type& k)
         {
             return base.erase(k);
         }
 
- iterator erase(iterator first, iterator last)
+ iterator erase(const_iterator first, const_iterator last)
         {
             return iterator(base.erase(get(first), get(last)));
         }
 
- const_iterator erase(const_iterator first, const_iterator last)
- {
- return const_iterator(base.erase(get(first), get(last)));
- }
-
         void clear()
         {
             base.clear();

Modified: sandbox/unordered/boost/unordered_set.hpp
==============================================================================
--- sandbox/unordered/boost/unordered_set.hpp (original)
+++ sandbox/unordered/boost/unordered_set.hpp 2007-10-11 19:49:31 EDT (Thu, 11 Oct 2007)
@@ -155,9 +155,9 @@
                     base.insert(obj));
         }
 
- const_iterator insert(const_iterator hint, const value_type& obj)
+ iterator insert(const_iterator hint, const value_type& obj)
         {
- return const_iterator(base.insert(get(hint), obj));
+ return iterator(base.insert(get(hint), obj));
         }
 
         template <class InputIterator>
@@ -166,9 +166,9 @@
             base.insert(first, last);
         }
 
- const_iterator erase(const_iterator position)
+ iterator erase(const_iterator position)
         {
- return const_iterator(base.erase(get(position)));
+ return iterator(base.erase(get(position)));
         }
 
         size_type erase(const key_type& k)
@@ -176,9 +176,9 @@
             return base.erase(k);
         }
 
- const_iterator erase(const_iterator first, const_iterator last)
+ iterator erase(const_iterator first, const_iterator last)
         {
- return const_iterator(base.erase(get(first), get(last)));
+ return iterator(base.erase(get(first), get(last)));
         }
 
         void clear()
@@ -439,9 +439,9 @@
             return iterator(base.insert(obj));
         }
 
- const_iterator insert(const_iterator hint, const value_type& obj)
+ iterator insert(const_iterator hint, const value_type& obj)
         {
- return const_iterator(base.insert(get(hint), obj));
+ return iterator(base.insert(get(hint), obj));
         }
 
         template <class InputIterator>
@@ -450,9 +450,9 @@
             base.insert(first, last);
         }
 
- const_iterator erase(const_iterator position)
+ iterator erase(const_iterator position)
         {
- return const_iterator(base.erase(get(position)));
+ return iterator(base.erase(get(position)));
         }
 
         size_type erase(const key_type& k)
@@ -460,9 +460,9 @@
             return base.erase(k);
         }
 
- const_iterator erase(const_iterator first, const_iterator last)
+ iterator erase(const_iterator first, const_iterator last)
         {
- return const_iterator(base.erase(get(first), get(last)));
+ return iterator(base.erase(get(first), get(last)));
         }
 
         void clear()

Modified: sandbox/unordered/libs/unordered/test/objects/minimal.hpp
==============================================================================
--- sandbox/unordered/libs/unordered/test/objects/minimal.hpp (original)
+++ sandbox/unordered/libs/unordered/test/objects/minimal.hpp 2007-10-11 19:49:31 EDT (Thu, 11 Oct 2007)
@@ -125,9 +125,9 @@
     {
         friend class allocator<T>;
 
- T* ptr_;
+ T const* ptr_;
 
- const_ptr(T* ptr) : ptr_(ptr) {}
+ const_ptr(T const* ptr) : ptr_(ptr) {}
     public:
         const_ptr() : ptr_(0) {}
         const_ptr(ptr<T> const& x) : ptr_(x.ptr_) {}
@@ -135,12 +135,12 @@
         typedef void (const_ptr::*bool_type)() const;
         void this_type_does_not_support_comparisons() const {}
 
- T& operator*() const { return *ptr_; }
- T* operator->() const { return ptr_; }
+ T const& operator*() const { return *ptr_; }
+ T const* operator->() const { return ptr_; }
         const_ptr& operator++() { ++ptr_; return *this; }
         const_ptr operator++(int) { const_ptr tmp(*this); ++ptr_; return tmp; }
         const_ptr operator+(int s) const { return const_ptr(ptr_ + s); }
- T& operator[](int s) const { return ptr_[s]; }
+ T const& operator[](int s) const { return ptr_[s]; }
         bool operator!() const { return !ptr_; }
 
         operator bool_type() const {

Modified: sandbox/unordered/libs/unordered/test/unordered/compile_tests.cpp
==============================================================================
--- sandbox/unordered/libs/unordered/test/unordered/compile_tests.cpp (original)
+++ sandbox/unordered/libs/unordered/test/unordered/compile_tests.cpp 2007-10-11 19:49:31 EDT (Thu, 11 Oct 2007)
@@ -144,10 +144,8 @@
     test::check_return_type<hasher>::equals(b.hash_function());
     test::check_return_type<key_equal>::equals(b.key_eq());
 
- iterator q = a.begin();
- const_iterator r = a.begin();
+ const_iterator q = a.cbegin();
     test::check_return_type<iterator>::equals(a.insert(q, t));
- test::check_return_type<const_iterator>::equals(a.insert(r, t));
 
     // TODO: void return?
     a.insert(i, j);
@@ -156,23 +154,13 @@
     BOOST_TEST(a.empty());
     if(a.empty()) {
         a.insert(t);
- q = a.begin();
+ q = a.cbegin();
         test::check_return_type<iterator>::equals(a.erase(q));
     }
 
- BOOST_TEST(a.empty());
- if(a.empty()) {
- a.insert(t);
- r = a.begin();
- test::check_return_type<const_iterator>::equals(a.erase(r));
- }
-
- iterator q1 = a.begin(), q2 = a.end();
+ const_iterator q1 = a.cbegin(), q2 = a.cend();
     test::check_return_type<iterator>::equals(a.erase(q1, q2));
 
- const_iterator r1 = a.begin(), r2 = a.end();
- test::check_return_type<const_iterator>::equals(a.erase(r1, r2));
-
     // TODO: void return?
     a.clear();
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk