[squid-dev] [PATCH] SBuf const iterator fixes
Amos Jeffries
squid3 at treenet.co.nz
Mon Feb 8 18:18:50 UTC 2016
The SBufIterator is mostly actually a const iterator. But not quite.
The point of difference from const_iterator is the operator*() API which
is also different from the normal itertor API in that is returns a char
instead of a char& or const char &.
The attached patch fixes that API making the iterator equivalent to
const_iterator for the subset of iterator API that it does present.
This has side effects on the reverse iterator and SBuf begin/end
methods. Which are also const'ified.
There appears to be no built-time or unit test identified problems from
this change. IT passes the build farm QA easily.
Are there any objections to fast-tracking this merge? If not I hope to
apply this in the next day or two.
Amos
-------------- next part --------------
=== modified file 'src/SBuf.h'
--- src/SBuf.h 2016-01-01 00:12:18 +0000
+++ src/SBuf.h 2016-02-08 11:08:07 +0000
@@ -83,7 +83,7 @@
class CharacterSet;
class SBuf;
-/** Forward input iterator for SBufs
+/** Forward input const_iterator for SBufs
*
* Please note that any operation on the underlying SBuf may invalidate
* all iterators over it, resulting in undefined behavior by them.
@@ -96,7 +96,7 @@
bool operator==(const SBufIterator &s) const;
bool operator!=(const SBufIterator &s) const;
- char operator*() const { return *iter; }
+ const char &operator*() const { return *iter; }
SBufIterator& operator++() { ++iter; return *this; }
protected:
@@ -105,7 +105,7 @@
const char *iter;
};
-/** Reverse input iterator for SBufs
+/** Reverse input const_iterator for SBufs
*
* Please note that any operation on the underlying SBuf may invalidate
* all iterators over it, resulting in undefined behavior by them.
@@ -115,7 +115,7 @@
friend class SBuf;
public:
SBufReverseIterator& operator++() { --iter; return *this;}
- char operator*() const { return *(iter-1); }
+ const char &operator*() const { return *(iter-1); }
protected:
SBufReverseIterator(const SBuf &s, size_type sz) : SBufIterator(s,sz) {}
};
@@ -130,8 +130,8 @@
{
public:
typedef MemBlob::size_type size_type;
- typedef SBufIterator iterator;
- typedef SBufReverseIterator reverse_iterator;
+ typedef SBufIterator const_iterator;
+ typedef SBufReverseIterator const_reverse_iterator;
static const size_type npos = 0xffffffff; // max(uint32_t)
/// Maximum size of a SBuf. By design it MUST be < MAX(size_type)/2. Currently 256Mb.
@@ -648,20 +648,20 @@
/// std::string export function
std::string toStdString() const { return std::string(buf(),length()); }
- iterator begin() {
- return iterator(*this, 0);
- }
-
- iterator end() {
- return iterator(*this, length());
- }
-
- reverse_iterator rbegin() {
- return reverse_iterator(*this, length());
- }
-
- reverse_iterator rend() {
- return reverse_iterator(*this, 0);
+ const_iterator begin() const {
+ return const_iterator(*this, 0);
+ }
+
+ const_iterator end() const {
+ return const_iterator(*this, length());
+ }
+
+ const_reverse_iterator rbegin() const {
+ return const_reverse_iterator(*this, length());
+ }
+
+ const_reverse_iterator rend() const {
+ return const_reverse_iterator(*this, 0);
}
// TODO: possibly implement erase() similar to std::string's erase
More information about the squid-dev
mailing list