aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2007-10-09 21:14:41 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2007-10-09 21:14:41 +0000
commita7ebcdbeae9d62fe0c867082dceaf092dc621e22 (patch)
tree4f0b24435b2caa64e4d4a5edc8b203c96221dac4
parenta5db25fe888abe1b13ccde5d952e39cdb0fa30d7 (diff)
downloadpaludis-a7ebcdbeae9d62fe0c867082dceaf092dc621e22.tar.gz
paludis-a7ebcdbeae9d62fe0c867082dceaf092dc621e22.tar.xz
Make the member a template parameter.
-rw-r--r--src/clients/reconcilio/util/iterator.hh40
-rw-r--r--src/clients/reconcilio/util/iterator_TEST.cc12
2 files changed, 28 insertions, 24 deletions
diff --git a/src/clients/reconcilio/util/iterator.hh b/src/clients/reconcilio/util/iterator.hh
index 0baf47b..25ccbd6 100644
--- a/src/clients/reconcilio/util/iterator.hh
+++ b/src/clients/reconcilio/util/iterator.hh
@@ -24,20 +24,17 @@
#include <iterator>
-template <typename Value_, typename Iterator_>
+template <typename Value_, typename Iterator_, Value_ std::iterator_traits<Iterator_>::value_type::* member_>
class MemberIterator :
public std::iterator<std::forward_iterator_tag, const Value_>,
public paludis::equality_operators::HasEqualityOperators
{
private:
Iterator_ _it;
- typedef Value_ std::iterator_traits<Iterator_>::value_type::* Member;
- Member _member;
public:
- MemberIterator(Iterator_ it, Member member) :
- _it(it),
- _member(member)
+ MemberIterator(Iterator_ it) :
+ _it(it)
{
}
@@ -54,39 +51,46 @@ class MemberIterator :
MemberIterator operator++ (int)
{
- return MemberIterator(_it++, _member);
+ return MemberIterator(_it++);
}
typename std::iterator_traits<MemberIterator>::reference operator* () const
{
- return (*_it).*_member;
+ return (*_it).*member_;
}
typename std::iterator_traits<MemberIterator>::pointer operator-> () const
{
- return &((*_it).*_member);
+ return &((*_it).*member_);
}
};
-template <typename Value_, typename Iterator_>
-inline MemberIterator<Value_, Iterator_>
-member_iterator(const Iterator_ & it, Value_ std::iterator_traits<Iterator_>::value_type::* member)
+template <typename Iterator_>
+struct FirstIterator
{
- return MemberIterator<Value_, Iterator_>(it, member);
-}
+ typedef MemberIterator<typename std::iterator_traits<Iterator_>::value_type::first_type,
+ Iterator_, &std::iterator_traits<Iterator_>::value_type::first> Type;
+};
template <typename Iterator_>
-inline MemberIterator<typename std::iterator_traits<Iterator_>::value_type::first_type, Iterator_>
+inline typename FirstIterator<Iterator_>::Type
first_iterator(Iterator_ it)
{
- return member_iterator(it, &std::iterator_traits<Iterator_>::value_type::first);
+ return typename FirstIterator<Iterator_>::Type(it);
}
template <typename Iterator_>
-inline MemberIterator<typename std::iterator_traits<Iterator_>::value_type::second_type, Iterator_>
+struct SecondIterator
+{
+ typedef MemberIterator<typename std::iterator_traits<Iterator_>::value_type::second_type,
+ Iterator_, &std::iterator_traits<Iterator_>::value_type::second> Type;
+};
+
+template <typename Iterator_>
+inline typename SecondIterator<Iterator_>::Type
second_iterator(Iterator_ it)
{
- return member_iterator(it, &std::iterator_traits<Iterator_>::value_type::second);
+ return typename SecondIterator<Iterator_>::Type(it);
}
#endif
diff --git a/src/clients/reconcilio/util/iterator_TEST.cc b/src/clients/reconcilio/util/iterator_TEST.cc
index a589fb7..b11deb1 100644
--- a/src/clients/reconcilio/util/iterator_TEST.cc
+++ b/src/clients/reconcilio/util/iterator_TEST.cc
@@ -48,13 +48,13 @@ namespace test_cases
v.push_back(std::pair<std::string, std::string>("four", "IV"));
v.push_back(std::pair<std::string, std::string>("five", "V"));
- MemberIterator<std::string, V::iterator> it = first_iterator(v.begin());
+ FirstIterator<V::iterator>::Type it = first_iterator(v.begin());
TEST_CHECK(it == it);
TEST_CHECK(! (it != it));
TEST_CHECK_EQUAL(*it, "one");
TEST_CHECK_EQUAL(it->length(), 3U);
- MemberIterator<std::string, V::iterator> it2(it);
+ FirstIterator<V::iterator>::Type it2(it);
TEST_CHECK(it == it2);
TEST_CHECK(! (it != it2));
TEST_CHECK_EQUAL(*++it2, "two");
@@ -63,7 +63,7 @@ namespace test_cases
TEST_CHECK(it != it2);
TEST_CHECK(! (it == it2));
- MemberIterator<std::string, V::iterator> it3(it2);
+ FirstIterator<V::iterator>::Type it3(it2);
TEST_CHECK(it2 == it3++);
TEST_CHECK(it2 != it3);
TEST_CHECK_EQUAL(*it3, "three");
@@ -93,13 +93,13 @@ namespace test_cases
m["IV"] = "four";
m["V"] = "five";
- MemberIterator<std::string, M::iterator> it = second_iterator(m.begin());
+ SecondIterator<M::iterator>::Type it = second_iterator(m.begin());
TEST_CHECK(it == it);
TEST_CHECK(! (it != it));
TEST_CHECK_EQUAL(*it, "one");
TEST_CHECK_EQUAL(it->length(), 3U);
- MemberIterator<std::string, M::iterator> it2(it);
+ SecondIterator<M::iterator>::Type it2(it);
TEST_CHECK(it == it2);
TEST_CHECK(! (it != it2));
TEST_CHECK_EQUAL(*++it2, "two");
@@ -108,7 +108,7 @@ namespace test_cases
TEST_CHECK(it != it2);
TEST_CHECK(! (it == it2));
- MemberIterator<std::string, M::iterator> it3(it2);
+ SecondIterator<M::iterator>::Type it3(it2);
TEST_CHECK(it2 == it3++);
TEST_CHECK(it2 != it3);
TEST_CHECK_EQUAL(*it3, "three");