17b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// -*- C++ -*-
27b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh
37b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// Copyright (C) 2007-2014 Free Software Foundation, Inc.
47b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh//
57b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// This file is part of the GNU ISO C++ Library.  This library is free
67b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// software; you can redistribute it and/or modify it under the terms
77b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// of the GNU General Public License as published by the Free Software
87b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// Foundation; either version 3, or (at your option) any later
97b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// version.
107b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh
117b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// This library is distributed in the hope that it will be useful, but
127b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// WITHOUT ANY WARRANTY; without even the implied warranty of
137b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// General Public License for more details.
157b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh
167b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// Under Section 7 of GPL version 3, you are granted additional
177b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// permissions described in the GCC Runtime Library Exception, version
187b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// 3.1, as published by the Free Software Foundation.
197b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh
207b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// You should have received a copy of the GNU General Public License and
217b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// a copy of the GCC Runtime Library Exception along with this program;
227b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
237b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// <http://www.gnu.org/licenses/>.
247b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh
257b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh/** @file parallel/checkers.h
267b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh *  @brief Routines for checking the correctness of algorithm results.
277b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh *  This file is a GNU parallel extension to the Standard C++ Library.
287b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh */
297b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh
307b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh// Written by Johannes Singler.
317b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh
327b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh#ifndef _GLIBCXX_PARALLEL_CHECKERS_H
337b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh#define _GLIBCXX_PARALLEL_CHECKERS_H 1
347b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh
357b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh#include <cstdio>
367b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh#include <bits/stl_algobase.h>
377b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh#include <bits/stl_function.h>
387b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh
397b9b0e19b31944fce201a273083eaca38e477580Andrew Hsiehnamespace __gnu_parallel
407b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh{
417b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh  /**
427b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh   * @brief Check whether @c [__begin, @c __end) is sorted according
437b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh   * to @c __comp.
447b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh   * @param __begin Begin iterator of sequence.
457b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh   * @param __end End iterator of sequence.
467b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh   * @param __comp Comparator.
477b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh   * @return @c true if sorted, @c false otherwise.
487b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh   */
497b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh  template<typename _IIter, typename _Compare>
507b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh    bool
517b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh    __is_sorted(_IIter __begin, _IIter __end, _Compare __comp)
527b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh    {
537b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh      if (__begin == __end)
547b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh        return true;
557b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh
567b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh      _IIter __current(__begin), __recent(__begin);
577b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh
587b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh      unsigned long long __position = 1;
597b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh      for (__current++; __current != __end; __current++)
607b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh        {
617b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh          if (__comp(*__current, *__recent))
627b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh            {
637b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh              return false;
647b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh            }
657b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh          __recent = __current;
667b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh          __position++;
677b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh        }
687b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh
697b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh      return true;
707b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh    }
717b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh}
727b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh
737b9b0e19b31944fce201a273083eaca38e477580Andrew Hsieh#endif /* _GLIBCXX_PARALLEL_CHECKERS_H */
74