diff --git a/TinySTL/Algorithm.h b/TinySTL/Algorithm.h index af05fdc..1007f85 100644 --- a/TinySTL/Algorithm.h +++ b/TinySTL/Algorithm.h @@ -333,6 +333,18 @@ namespace TinySTL{ } return n; } + //********** [count_if] ****************************** + //********* [Algorithm Complexity: O(N)] **************** + template + typename iterator_traits::difference_type + count_if(InputIterator first, InputIterator last, UnaryPredicate pred){ + typename iterator_traits::difference_type n = 0; + for (; first != last; ++first){ + if (pred(*first)) + ++n; + } + return n; + } }