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_IF_HPP
00008 #define INSTIGATE_STL_COUNT_IF_HPP
00009
00059
00060 #include "concept.hpp"
00061 #include "_basis.hpp"
00062
00063
00064
00065
00066
00067
00068 namespace instigate {
00069 namespace stl {
00070 template <typename I, typename P>
00071 typename stl::single_pass_iterator::interface<I>::
00072 difference_type count_if(I, I, P);
00073
00074 template <typename I, typename P, typename S>
00075 void count_if(I, I, P, S&);
00076 }
00077 }
00078
00106 template <typename I, typename P>
00107 typename instigate::stl::single_pass_iterator::interface<I>::difference_type
00108 instigate::stl::count_if(I b, I e, P p)
00109 {
00110 CHECK(stl::single_pass_iterator::requirements<I>);
00111 CHECK(stl::readable_iterator::requirements<I>);
00112 CHECK(stl::unary_predicate::requirements<P>);
00113 typename stl::single_pass_iterator::interface<I>::difference_type n;
00114 n = 0;
00115 for (; !(equal(b, e)); increment(b)) {
00116 if (invoke_predicate(p, const_dereference(b))) {
00117 ++n;
00118 }
00119 }
00120 return n;
00121 }
00122
00149 template <typename I, typename P, typename S>
00150 void instigate::stl::count_if(I b, I e, P p, S& n)
00151 {
00152 CHECK(stl::single_pass_iterator::requirements<I>);
00153 CHECK(stl::readable_iterator::requirements<I>);
00154 CHECK(stl::unary_predicate::requirements<P>);
00155 for (; !(equal(b, e)); increment(b)) {
00156 if (invoke_predicate(p, const_dereference(b))) {
00157 ++n;
00158 }
00159 }
00160 }
00161
00162
00163
00164 #endif // INSTIGATE_STL_COUNT_IF_HPP