std::end(Range);
}
+/// Wrapper function around std::count to count the number of times an element
+/// \p Element occurs in the given range \p Range.
+template <typename R, typename E>
+auto count(R &&Range, const E &Element) -> typename std::iterator_traits<
+ decltype(std::begin(Range))>::difference_type {
+ return std::count(std::begin(Range), std::end(Range), Element);
+}
+
/// Wrapper function around std::count_if to count the number of times an
/// element satisfying a given predicate occurs in a range.
template <typename R, typename UnaryPredicate>
EXPECT_EQ("Tes", std::get<1>(Values));
EXPECT_EQ('Y', std::get<2>(Values));
}
+
+TEST(STLExtrasTest, CountAdaptor) {
+ std::vector<int> v;
+
+ v.push_back(1);
+ v.push_back(2);
+ v.push_back(1);
+ v.push_back(4);
+ v.push_back(3);
+ v.push_back(2);
+ v.push_back(1);
+
+ EXPECT_EQ(3, count(v, 1));
+ EXPECT_EQ(2, count(v, 2));
+ EXPECT_EQ(1, count(v, 3));
+ EXPECT_EQ(1, count(v, 4));
+}
}