00001
00002 #ifndef _INSTIGATE_STL_INTERNAL_HEADER_IN_ALGORITHM
00003 #error This is an internal header file used to implement Instigate STL.\
00004 It should never be included directly by a program.
00005 #endif
00006
00007 #ifndef INSTIGATE_STL_COUNT_HPP
00008 #define INSTIGATE_STL_COUNT_HPP
00009
00058
00059 #include "concept.hpp"
00060 #include "_basis.hpp"
00061
00062
00063
00064
00065
00066
00067 namespace instigate {
00068 namespace stl {
00069 template <typename I, typename V>
00070 typename instigate::stl::single_pass_iterator::interface<I>::
00071 difference_type count(I, I, const V&);
00072
00073 template <typename I, typename V, typename S>
00074 void count(I, I, const V&, S&);
00075 }
00076 }
00077
00108 template <typename I, typename V>
00109 typename instigate::stl::single_pass_iterator::interface<I>::difference_type
00110 instigate::stl::count(I b, I e, const V& v)
00111 {
00112 CHECK(stl::single_pass_iterator::requirements<I>);
00113 CHECK(stl::readable_iterator::requirements<I>);
00114 CHECK(instigate::generic::equality_comparable::requirements<typename
00115 readable_iterator::interface<I>::value_type>);
00116 CHECK(instigate::generic::equality_comparable::requirements<V>);
00117 typename stl::single_pass_iterator::interface<I>::
00118 difference_type n;
00119 n = 0;
00120 for (; !(equal(b, e)); increment(b)) {
00121 if (equal(const_dereference(b), v)) {
00122 ++n;
00123 }
00124 }
00125 return n;
00126 }
00127
00157 template <typename I, typename V, typename S>
00158 void instigate::stl::count(I b, I e, const V& v, S& n)
00159 {
00160 CHECK(stl::single_pass_iterator::requirements<I>);
00161 CHECK(stl::readable_iterator::requirements<I>);
00162 CHECK(instigate::generic::equality_comparable::requirements<typename
00163 readable_iterator::interface<I>::value_type>);
00164 CHECK(instigate::generic::equality_comparable::requirements<V>);
00165 for (; !(equal(b, e)); increment(b)) {
00166 if (equal(const_dereference(b), v)) {
00167 ++n;
00168 }
00169 }
00170 }
00171
00172
00173
00174 #endif // INSTIGATE_STL_COUNT_HPP