# checkers.h

Go to the documentation of this file.

    00001 // -*- C++ -*-
    00002
    00003 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
    00004 //
    00005 // This file is part of the GNU ISO C++ Library.  This library is free
    00006 // software; you can redistribute it and/or modify it under the terms
    00007 // of the GNU General Public License as published by the Free Software
    00008 // Foundation; either version 3, or (at your option) any later
    00009 // version.
    00010
    00011 // This library is distributed in the hope that it will be useful, but
    00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
    00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014 // General Public License for more details.
    00015
    00016 // Under Section 7 of GPL version 3, you are granted additional
    00017 // permissions described in the GCC Runtime Library Exception, version
    00018 // 3.1, as published by the Free Software Foundation.
    00019
    00020 // You should have received a copy of the GNU General Public License and
    00021 // a copy of the GCC Runtime Library Exception along with this program;
    00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    00023 // <http://www.gnu.org/licenses/>.
    00024
    00025 /** @file parallel/checkers.h
    00026  *  @brief Routines for checking the correctness of algorithm results.
    00027  *  This file is a GNU parallel extension to the Standard C++ Library.
    00028  */
    00029
    00030 // Written by Johannes Singler.
    00031
    00032 #ifndef _GLIBCXX_PARALLEL_CHECKERS_H
    00033 #define _GLIBCXX_PARALLEL_CHECKERS_H 1
    00034
    00035 #include <cstdio>
    00036 #include <bits/stl_algobase.h>
    00037 #include <bits/stl_function.h>
    00038
    00039 namespace __gnu_parallel
    00040 {
    00041   /**
    00042    * @brief Check whether @c [__begin, @c __end) is sorted according
    00043    * to @c __comp.
    00044    * @param __begin Begin iterator of sequence.
    00045    * @param __end End iterator of sequence.
    00046    * @param __comp Comparator.
    00047    * @return @c true if sorted, @c false otherwise.
    00048    */
    00049   template<typename _IIter, typename _Compare>
    00050     bool
    00051     __is_sorted(_IIter __begin, _IIter __end, _Compare __comp)
    00052     {
    00053       if (__begin == __end)
    00054         return true;
    00055
    00056       _IIter __current(__begin), __recent(__begin);
    00057
    00058       unsigned long long __position = 1;
    00059       for (__current++; __current != __end; __current++)
    00060         {
    00061           if (__comp(*__current, *__recent))
    00062             {
    00063               return false;
    00064             }
    00065           __recent = __current;
    00066           __position++;
    00067         }
    00068
    00069       return true;
    00070     }
    00071 }
    00072
    00073 #endif /* _GLIBCXX_PARALLEL_CHECKERS_H */