aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2008-04-02 02:15:00 +0000
committerJohannes Schickel2008-04-02 02:15:00 +0000
commitda9701d19b41705e39ead61bc56fed1439720216 (patch)
treef9cdc51910d5a26e1a8717dc52170d911d5051ed
parent8436943bfd4aace76c16a4c4404c5e9dbc0a41f0 (diff)
downloadscummvm-rg350-da9701d19b41705e39ead61bc56fed1439720216.tar.gz
scummvm-rg350-da9701d19b41705e39ead61bc56fed1439720216.tar.bz2
scummvm-rg350-da9701d19b41705e39ead61bc56fed1439720216.zip
Implemented transparent List::iterator to List::const_iterator conversion and updated our tests accordingly.
svn-id: r31357
-rw-r--r--common/list.h19
-rw-r--r--test/common/list.h16
2 files changed, 31 insertions, 4 deletions
diff --git a/common/list.h b/common/list.h
index 5629c40a0d..29e02188d7 100644
--- a/common/list.h
+++ b/common/list.h
@@ -54,6 +54,7 @@ public:
template <class t_T2>
class Iterator {
+ //template<class T> friend class Iterator;
friend class List<t_T>;
NodeBase *_node;
@@ -65,6 +66,14 @@ public:
public:
Iterator() : _node(0) {}
+ template<class T>
+ Iterator(const Iterator<T> &c) : _node(c._node) {}
+
+ template<class T>
+ Iterator<t_T2> &operator =(const Iterator<T> &c) {
+ _node = c._node;
+ return *this;
+ }
// Prefix inc
Iterator<t_T2> &operator++() {
@@ -90,7 +99,7 @@ public:
--(*this);
return tmp;
}
- t_T2& operator*() const {
+ t_T2 &operator*() const {
assert(_node);
#if (__GNUC__ == 2) && (__GNUC_MINOR__ >= 95)
return static_cast<List<t_T>::Node<t_T2> *>(_node)->_data;
@@ -98,15 +107,17 @@ public:
return static_cast<Node<t_T2>*>(_node)->_data;
#endif
}
- t_T2* operator->() const {
+ t_T2 *operator->() const {
return &(operator*());
}
- bool operator==(const Iterator<t_T2>& x) const {
+ template<class T>
+ bool operator==(const Iterator<T> &x) const {
return _node == x._node;
}
- bool operator!=(const Iterator<t_T2>& x) const {
+ template<class T>
+ bool operator!=(const Iterator<T> &x) const {
return _node != x._node;
}
};
diff --git a/test/common/list.h b/test/common/list.h
index c206dbe009..356693c33e 100644
--- a/test/common/list.h
+++ b/test/common/list.h
@@ -36,6 +36,7 @@ class ListTestSuite : public CxxTest::TestSuite
{
Common::List<int> container;
Common::List<int>::iterator iter;
+ Common::List<int>::const_iterator cIter;
// Fill the container with some random data
container.push_back(17);
@@ -46,19 +47,34 @@ class ListTestSuite : public CxxTest::TestSuite
// the order we expect them to be.
iter = container.begin();
+ cIter = container.begin();
+
+ TS_ASSERT( iter == cIter );
TS_ASSERT( *iter == 17 );
++iter;
+ ++cIter;
TS_ASSERT( iter != container.end() );
+ TS_ASSERT( cIter != container.end() );
+ TS_ASSERT( iter == cIter );
TS_ASSERT( *iter == 33 );
++iter;
+ ++cIter;
TS_ASSERT( iter != container.end() );
+ TS_ASSERT( cIter != container.end() );
+ TS_ASSERT( iter == cIter );
// Also test the postinc
TS_ASSERT( *iter == -11 );
iter++;
+ cIter++;
TS_ASSERT( iter == container.end() );
+ TS_ASSERT( cIter == container.end() );
+ TS_ASSERT( iter == cIter );
+
+ cIter = iter;
+ TS_ASSERT( iter == cIter );
}
void test_insert( void )