Sorry for dropping the ball on reviewing this patch.

The changes look good to me. The two things that are missing
and that we can't commit the patch without are: 1) tests and
2) a ChangeLog entry.

We haven't ported all the container tests to the new driver
so you won't be able to simply enhance existing tests to
exercise all the functions but you should be able to do so
for deque, list, and string. Take a look at the tests for
these three containers to see if you can figure out how to
enhance them. If you need help feel free to ask. One of us
(presumably Farid, as he has the most experience with these
tests) should be able to answer your questions.

As for the other containers, we'll need to remember to add
tests for these new functions when we get around to porting
(or writing from scratch) the tests for those.

Martin

Mark Brown wrote:
How frustrating!

Here it is again, this time inline:

Index: /home/mbrown/stdcxx/include/map
===================================================================
--- /home/mbrown/stdcxx/include/map     (revision 516799)
+++ /home/mbrown/stdcxx/include/map     (working copy)
@@ -167,6 +167,10 @@
         return _C_rep.begin ();
     }
+ const_iterator cbegin () const {
+        return _C_rep.begin ();
+    }
+
     iterator end () {
         return _C_rep.end ();
     }
@@ -175,6 +179,10 @@
         return _C_rep.end ();
     }
+ const_iterator cend () const {
+        return _C_rep.end ();
+    }
+
     reverse_iterator rbegin () {
         return _C_rep.rbegin ();
     }
@@ -183,6 +191,10 @@
         return _C_rep.rbegin ();
     }
+ const_reverse_iterator crbegin () const {
+        return _C_rep.rbegin ();
+    }
+
     reverse_iterator rend () {
         return _C_rep.rend ();
     }
@@ -191,6 +203,10 @@
         return _C_rep.rend ();
     }
+ const_reverse_iterator crend () const {
+        return _C_rep.rend ();
+    }
+
     bool empty () const {
         return _C_rep.empty ();
     }
Index: /home/mbrown/stdcxx/include/set
===================================================================
--- /home/mbrown/stdcxx/include/set     (revision 516799)
+++ /home/mbrown/stdcxx/include/set     (working copy)
@@ -160,12 +160,16 @@
     //
     iterator                 begin  ()       { return _C_rep.begin ();  }
     const_iterator           begin  () const { return _C_rep.begin ();  }
+    const_iterator           cbegin () const { return _C_rep.begin ();  }
     iterator                 end    ()       { return _C_rep.end ();    }
     const_iterator           end    () const { return _C_rep.end ();    }
+    const_iterator           cend   () const { return _C_rep.end ();    }
reverse_iterator rbegin () { return _C_rep.rbegin (); } const_reverse_iterator rbegin () const { return _C_rep.rbegin (); } + const_reverse_iterator crbegin() const { return _C_rep.rbegin (); } reverse_iterator rend () { return _C_rep.rend (); }
     const_reverse_iterator   rend   () const { return _C_rep.rend ();   }
+    const_reverse_iterator   crend  () const { return _C_rep.rend ();   }
//
     // capacity
Index: /home/mbrown/stdcxx/include/string
===================================================================
--- /home/mbrown/stdcxx/include/string  (revision 516799)
+++ /home/mbrown/stdcxx/include/string  (working copy)
@@ -214,6 +214,10 @@
         return _C_make_iter (_C_data);
     }
+ const_iterator cbegin () const {
+        return _C_make_iter (_C_data);
+    }
+
     iterator end () {
         // disable reference counting
         return begin () + size ();
@@ -223,6 +227,10 @@
         return _C_make_iter (_C_data + size ());
     }
+ const_iterator cend () const {
+        return _C_make_iter (_C_data + size ());
+    }
+
     reverse_iterator rbegin () {
         return reverse_iterator (end ());
     }
@@ -231,6 +239,10 @@
         return const_reverse_iterator (end ());
     }
+ const_reverse_iterator crbegin () const {
+        return const_reverse_iterator (end ());
+    }
+
     reverse_iterator rend () {
         return reverse_iterator (begin ());
     }
@@ -239,6 +251,10 @@
         return const_reverse_iterator (begin ());
     }
+ const_reverse_iterator crend () const {
+        return const_reverse_iterator (begin ());
+    }
+
     size_type size () const {
         return _C_pref ()->size ();
     }
Index: /home/mbrown/stdcxx/include/vector
===================================================================
--- /home/mbrown/stdcxx/include/vector  (revision 516799)
+++ /home/mbrown/stdcxx/include/vector  (working copy)
@@ -259,6 +259,10 @@
         return _C_make_iter (_C_begin);
     }
+ const_iterator cbegin () const {
+        return _C_make_iter (_C_begin);
+    }
+
     iterator end () {
         return _C_make_iter (_C_end);
     }
@@ -267,6 +271,10 @@
         return _C_make_iter (_C_end);
     }
+ const_iterator cend () const {
+        return _C_make_iter (_C_end);
+    }
+
reverse_iterator rbegin () { return reverse_iterator (end ());
     }
@@ -275,6 +283,10 @@
         return const_reverse_iterator (end ());
     }
+ const_reverse_iterator crbegin () const { + return const_reverse_iterator (end ());
+    }
+
reverse_iterator rend () { return reverse_iterator (begin ());
     }
@@ -283,6 +295,10 @@
         return const_reverse_iterator (begin ());
     }
+ const_reverse_iterator crend () const { + return const_reverse_iterator (begin ());
+    }
+
     size_type size () const {
         return size_type (_C_end - _C_begin);
     }
@@ -1279,23 +1295,45 @@
     // iterators
     //
     iterator       begin ()       { return _C_begin; }
- const_iterator begin () const - { return const_iterator(_C_begin._C_p,_C_begin._C_offset); }
+
+    const_iterator begin () const {
+      return const_iterator (_C_begin._C_p, _C_begin._C_offset);
+    }
+
+    const_iterator cbegin () const {
+      return const_iterator (_C_begin._C_p, _C_begin._C_offset);
+    }
+
     iterator       end   ()       { return _C_end; }
- const_iterator end () const - { return const_iterator(_C_end._C_p,_C_end._C_offset); } + const_iterator end () const {
+      return const_iterator(_C_end._C_p,_C_end._C_offset);
+    }
+
+    const_iterator cend () const {
+      return const_iterator (_C_end._C_p, _C_end._C_offset);
+    }
+
     reverse_iterator       rbegin () { return reverse_iterator(end()); }
     const_reverse_iterator rbegin () const
{ return const_reverse_iterator(end()); }
+
+ const_reverse_iterator crbegin () const { + return const_reverse_iterator(end()); + }
+
     reverse_iterator       rend () { return reverse_iterator(begin()); }
     const_reverse_iterator rend () const
{ return const_reverse_iterator(begin()); } + const_reverse_iterator crend () const { + return const_reverse_iterator(begin()); + }
+
     //
     // capacity
     //
Index: /home/mbrown/stdcxx/include/deque
===================================================================
--- /home/mbrown/stdcxx/include/deque   (revision 516799)
+++ /home/mbrown/stdcxx/include/deque   (working copy)
@@ -516,6 +516,10 @@
         return _C_make_iter (_C_beg);
     }
+ const_iterator cbegin () const {
+        return _C_make_iter (_C_beg);
+    }
+
     iterator end () {
         return _C_make_iter (_C_end);
     }
@@ -524,6 +528,10 @@
         return _C_make_iter (_C_end);
     }
+ const_iterator cend () const {
+        return _C_make_iter (_C_end);
+    }
+
     reverse_iterator rbegin () {
         return reverse_iterator (end ());
     }
@@ -532,6 +540,10 @@
         return const_reverse_iterator (end ());
     }
+ const_reverse_iterator crbegin () const { + return const_reverse_iterator (end ());
+    }
+
reverse_iterator rend () { return reverse_iterator (begin ());
     }
@@ -540,6 +552,10 @@
         return const_reverse_iterator (begin ());
     }
+ const_reverse_iterator crend () const { + return const_reverse_iterator (begin ());
+    }
+
     bool empty () const {
         return    _C_beg._C_node == _C_end._C_node
                && _C_beg._C_cur == _C_end._C_cur;
Index: /home/mbrown/stdcxx/include/list
===================================================================
--- /home/mbrown/stdcxx/include/list    (revision 516799)
+++ /home/mbrown/stdcxx/include/list    (working copy)
@@ -504,6 +504,10 @@
         return _C_make_iter ((*_C_node)._C_next);
     }
+ const_iterator cbegin () const {
+        return _C_make_iter ((*_C_node)._C_next);
+    }
+
     iterator end () {
         return _C_make_iter (_C_node);
     }
@@ -512,6 +516,10 @@
         return _C_make_iter (_C_node);
     }
+ const_iterator cend () const {
+        return _C_make_iter (_C_node);
+    }
+
reverse_iterator rbegin () { return reverse_iterator (end ());
     }
@@ -520,6 +528,10 @@
         return const_reverse_iterator (end ());
     }
+ const_reverse_iterator crbegin () const { + return const_reverse_iterator (end ());
+    }
+
reverse_iterator rend () { return reverse_iterator (begin ());
     }
@@ -528,6 +540,10 @@
         return const_reverse_iterator (begin ());
     }
+ const_reverse_iterator crend () const {
+        return const_reverse_iterator (begin ());
+    }
+
     bool empty () const {
         return 0 == size ();
     }


-- Mark


-----Original Message-----
From: [EMAIL PROTECTED]
Sent: Tue, 13 Mar 2007 10:33:40 -0600
To: [email protected]
Subject: Re: [PATCH] Re: new container member functions cbegin() and
cend()

Mark Brown wrote:
Attached is my first attempt at a patch implementing these functions.
Please let me know if I've missed something. The ChangeLong entry is
here:
Sorry Mark but the patch got stripped again.

Martin

2007-03-13  Mark Brown <[EMAIL PROTECTED]>

        STDCXX-335
        * map (cbegin, cend, crbegin, crend): Implemented new accessor
functions.
        * set: Same.
        * string: Same.
        * vector: Same.
        * deque: Same.
        * list: Same.

-- Mark

-----Original Message-----
From: [EMAIL PROTECTED]
Sent: Sat, 10 Mar 2007 10:12:09 -0800
To: [email protected], [email protected]
Subject: Re: new container member functions cbegin() and cend()

-----Original Message-----
From: [EMAIL PROTECTED]
Sent: Fri, 09 Mar 2007 13:44:49 -0700
To: [email protected]
Subject: Re: new container member functions cbegin() and cend()

Mark Brown wrote:
The next C++ standard adds a couple of new container member
functions,
cbegin() and cend(), that will make it easier to retrieve const
iterators from non-const container objects. Are there any plans to
add
these functions to stdcxx?
I assume you're referring to the Working Draft of the Standard for
Programming Language C++:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2134.pdf

and the functions are those proposed in Walter Brown's Proposal
to Improve const_iterator Use from C++0X:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1674.pdf
Yes, the functions from Alternative 1 are the ones I was referring
to. They will become especially handy when the "auto" feature is
available in compilers. Does anyone know of a compiler that
supports this use of auto?

I have no immediate plans to implement these functions but we
certainly expect and plan to implement the new C++ standard by
the time it comes out.

If you would like to submit a patch with these functions or any
other feature that's expected to be in the next standard you
are most welcome to do so. Small extensions like this one might
be okay for trunk. Bigger features will probably be more
appropriate for a yet-to-be created branch as suggested in
STDCXX-299: https://issues.apache.org/jira/browse/STDCXX-299
I will work on a patch.

-- Mark

Martin

-- Mark

____________________________________________________________
GET FREE 5GB ONLINE STORAGE - Safely store your documents, photos and music 
online!
Visit http://www.inbox.com/storage to find out more!

Reply via email to