aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Mark Loeser <halcy0n@gentoo.org> 2006-02-06 15:34:47 +0000
committerAvatar Mark Loeser <halcy0n@gentoo.org> 2006-02-06 15:34:47 +0000
commite669b0130a39065105ec356578701e84e34172a0 (patch)
treefc9d07441f07ab767719cb6c516158896e1a075d
parent0057f20a44280ca564e0142f64dedb847d1ace8b (diff)
downloadpaludis-e669b0130a39065105ec356578701e84e34172a0.tar.gz
paludis-e669b0130a39065105ec356578701e84e34172a0.tar.xz
Added SelectSecond and tests
-rw-r--r--paludis/transform_insert_iterator.hh14
-rw-r--r--paludis/transform_insert_iterator_TEST.cc20
2 files changed, 34 insertions, 0 deletions
diff --git a/paludis/transform_insert_iterator.hh b/paludis/transform_insert_iterator.hh
index 1e1d16e..fd5f273 100644
--- a/paludis/transform_insert_iterator.hh
+++ b/paludis/transform_insert_iterator.hh
@@ -138,6 +138,20 @@ namespace paludis
}
};
+ /**
+ * Convenience class: select the second item of a pair.
+ */
+ template <typename A_, typename B_>
+ struct SelectSecond :
+ std::unary_function<A_, std::pair<A_, B_> >
+ {
+ /// Carry out the selection.
+ A_ operator() (const std::pair<A_, B_> & p) const
+ {
+ return p.second;
+ }
+ };
+
}
#endif
diff --git a/paludis/transform_insert_iterator_TEST.cc b/paludis/transform_insert_iterator_TEST.cc
index bff6def..63b3e4b 100644
--- a/paludis/transform_insert_iterator_TEST.cc
+++ b/paludis/transform_insert_iterator_TEST.cc
@@ -72,5 +72,25 @@ namespace test_cases
}
}
} test_transform_insert_iterator;
+
+ /**
+ * \test Test SelectFirst and SelectSecond.
+ *
+ * \ingroup Test
+ */
+ struct SimpleSelectPairTest : TestCase
+ {
+ SimpleSelectPairTest() : TestCase("Simple SelectFirst and SelectSecond") {}
+
+ void run()
+ {
+ std::pair<int,int> p(1,2);
+ SelectFirst<int,int> f;
+ SelectSecond<int,int> s;
+
+ TEST_CHECK(f(p) == 1);
+ TEST_CHECK(s(p) == 2);
+ }
+ } test_select_pair;
}