vtf-logo

is_sorted.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00008 #if !defined(__ads_is_sorted_h__)
00009 #define __ads_is_sorted_h__
00010 
00011 #include "../defs.h"
00012 
00013 BEGIN_NAMESPACE_ADS
00014 
00015 //-----------------------------------------------------------------------------
00020 // @{
00021 
00023 template<typename ForwardIterator>
00024 inline
00025 bool
00026 is_sorted(ForwardIterator first, ForwardIterator last) {
00027   if (first == last) {
00028     return true;
00029   }
00030 
00031   ForwardIterator next = first;
00032   for (++next; next != last; first = next, ++next) {
00033     if (*next < *first) {
00034       return false;
00035     }
00036   }
00037   
00038   return true;
00039 }
00040 
00042 template<typename ForwardIterator, typename StrictWeakOrdering>
00043 inline
00044 bool
00045 is_sorted(ForwardIterator first, ForwardIterator last, 
00046           StrictWeakOrdering comp) {
00047   if (first == last) {
00048     return true;
00049   }
00050 
00051   ForwardIterator next = first;
00052   for (++next; next != last; first = next, ++next) {
00053     if (comp(*next, *first)) {
00054       return false;
00055     }
00056   }
00057 
00058   return true;
00059 }
00060 
00061 // @}
00062 
00063 END_NAMESPACE_ADS
00064 
00065 #endif

Generated on Fri Aug 24 12:55:26 2007 for Algorithms and Data Structures Package by  doxygen 1.4.7