KSS Utility
C++ general utilities
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
algorithm.hpp
Go to the documentation of this file.
1 // \file algorithm.hpp
2 // \author Steven W. Klassen (klassens@acm.org)
3 // \date Sat May 10 2003
4 // \brief Generic algorithms.
5 //
6 // This file contains a variety of generic algorithms, similar in style
7 // to those found in the <algorithms> header of the standard library.
8 //
9 // This file is Copyright (c) 2003 by Klassen Software Solutions. All rights reserved.
10 // Licensing follows the MIT License.
11 //
12 
19 #ifndef kssutil_algorithm_hpp
20 #define kssutil_algorithm_hpp
21 
22 #include <algorithm>
23 #include <utility>
24 #include <functional>
25 
26 namespace kss { namespace util {
27 
36  template <class InputIterator, class Operator, class Predicate>
37  Operator forEachIf(InputIterator first, InputIterator last, Operator f, Predicate p) {
38  while (first != last) {
39  if (p(*first)) f(*first);
40  ++first;
41  }
42  return f;
43  }
44 
52  template <class InputIterator, class InputIterator2, class BinaryPredicate>
53  bool notEqual(InputIterator first,
54  InputIterator last,
55  InputIterator2 first2,
56  BinaryPredicate bp)
57  {
58  std::pair<InputIterator, InputIterator2> p = std::mismatch(first, last, first2, bp);
59  return (p.first != last);
60  }
61 
72  template <class InputIterator, class InputIterator2>
73  inline bool notEqual(InputIterator first, InputIterator last, InputIterator2 first2) {
74  return notEqual(first, last, first2, std::equal_to<decltype(*first)>());
75  }
76 
77 }}
78 
79 #endif
Operator forEachIf(InputIterator first, InputIterator last, Operator f, Predicate p)
Definition: algorithm.hpp:37
bool notEqual(InputIterator first, InputIterator last, InputIterator2 first2, BinaryPredicate bp)
Definition: algorithm.hpp:53