Advertisement
Radfler

::equal

Apr 10th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <functional>
  2. #include <iterator>
  3.  
  4. template<typename ForwardIt, typename Compare>
  5. bool equal(ForwardIt first, ForwardIt last, Compare compare) {
  6.    
  7.     if(first == last) {
  8.         return true;
  9.     }
  10.  
  11.     ForwardIt next = std::next(first);
  12.  
  13.     while(next != last) {
  14.         if(compare(*first, *next)) {
  15.             ++first;
  16.             ++next;
  17.         } else {
  18.             return false;
  19.         }
  20.     }
  21.  
  22.     return true;
  23.  
  24. }
  25.  
  26. template<typename ForwardIt>
  27. bool equal(ForwardIt first, ForwardIt last) {
  28.     return ::equal(first, last, std::equal_to<>{ });
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement