checkers.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // -*- C++ -*-
  2. // Copyright (C) 2007-2022 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the terms
  6. // of the GNU General Public License as published by the Free Software
  7. // Foundation; either version 3, or (at your option) any later
  8. // version.
  9. // This library is distributed in the hope that it will be useful, but
  10. // WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. // General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file parallel/checkers.h
  21. * @brief Routines for checking the correctness of algorithm results.
  22. * This file is a GNU parallel extension to the Standard C++ Library.
  23. */
  24. // Written by Johannes Singler.
  25. #ifndef _GLIBCXX_PARALLEL_CHECKERS_H
  26. #define _GLIBCXX_PARALLEL_CHECKERS_H 1
  27. #include <cstdio>
  28. #include <bits/stl_algobase.h>
  29. #include <bits/stl_function.h>
  30. namespace __gnu_parallel
  31. {
  32. /**
  33. * @brief Check whether @c [__begin, @c __end) is sorted according
  34. * to @c __comp.
  35. * @param __begin Begin iterator of sequence.
  36. * @param __end End iterator of sequence.
  37. * @param __comp Comparator.
  38. * @return @c true if sorted, @c false otherwise.
  39. */
  40. template<typename _IIter, typename _Compare>
  41. bool
  42. __is_sorted(_IIter __begin, _IIter __end, _Compare __comp)
  43. {
  44. if (__begin == __end)
  45. return true;
  46. _IIter __current(__begin), __recent(__begin);
  47. for (__current++; __current != __end; __current++)
  48. {
  49. if (__comp(*__current, *__recent))
  50. {
  51. return false;
  52. }
  53. __recent = __current;
  54. }
  55. return true;
  56. }
  57. }
  58. #endif /* _GLIBCXX_PARALLEL_CHECKERS_H */