From c6bb642098ce2ece748de7b27c88ce46b4cd8723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Sun, 19 Oct 2014 17:40:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90find=5Fif=E5=92=8Cfind=5Fif?= =?UTF-8?q?=5Fnot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Algorithm.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/TinySTL/Algorithm.h b/TinySTL/Algorithm.h index 9d855e1..628758e 100644 --- a/TinySTL/Algorithm.h +++ b/TinySTL/Algorithm.h @@ -225,6 +225,26 @@ namespace TinySTL{ } return first; } + //********** [find_if] ************************* + //********* [Algorithm Complexity: O(N)] **************** + template + InputIterator find_if(InputIterator first, InputIterator last, UnaryPredicate pred){ + for (; first != last; ++first){ + if (pred(*first)) + break; + } + return first; + } + //********** [find_if_not] ************************* + //********* [Algorithm Complexity: O(N)] **************** + template + InputIterator find_if_not(InputIterator first, InputIterator last, UnaryPredicate pred){ + for (; first != last; ++first){ + if (!pred(*first)) + break; + } + return first; + } }