00001
00002 #ifndef _INSTIGATE_STL_INTERNAL_HEADER_IN_ALGORITHM
00003 #error This is an internal header file used to implement Instigate STL.\
00004 It should never be included directly by a program.
00005 #endif
00006
00007 #ifndef INSTIGATE_STL_IS_SORTED_HPP
00008 #define INSTIGATE_STL_IS_SORTED_HPP
00009
00059
00060 #include "concept.hpp"
00061 #include "_basis.hpp"
00062
00063
00064
00065
00066
00067
00068
00069 namespace instigate {
00070 namespace stl {
00071 template <typename F>
00072 bool is_sorted(F b, F e);
00073 template <typename F, typename BP>
00074 bool is_sorted(F b, F e, BP p);
00075 }
00076 }
00077
00106 template <typename F>
00107 bool instigate::stl::is_sorted(F b, F e)
00108 {
00109 namespace FI = instigate::stl::forward_iterator;
00110 namespace RI = instigate::stl::readable_iterator;
00111 namespace LT = instigate::generic::less_than_comparable;
00112 CHECK(FI::requirements<F>);
00113 CHECK(RI::requirements<F>);
00114 typedef typename RI::interface<F>::value_type value_type;
00115 CHECK(LT::requirements<value_type>);
00116 if (equal(b, e)) {
00117 return true;
00118 }
00119 char c[sizeof(F)];
00120 F* n = 0;
00121 assign(n, copy_constructor(c, b));
00122 assert(0 != n);
00123 increment(*n);
00124 for (; !equal(*n, e); assign(b, *n), increment(*n)) {
00125 if (less_than(const_dereference(*n), const_dereference(b))) {
00126 return false;
00127 }
00128 }
00129 return true;
00130 }
00131
00166 template <typename F, typename BP>
00167 bool instigate::stl::is_sorted(F b, F e, BP p)
00168 {
00169 namespace FI = instigate::stl::forward_iterator;
00170 namespace RI = instigate::stl::readable_iterator;
00171 namespace BPI = instigate::stl::binary_predicate;
00172 CHECK(FI::requirements<F>);
00173 CHECK(RI::requirements<F>);
00174 CHECK(BPI::requirements<BP>);
00175 typedef typename RI::interface<F>::value_type value_type;
00176 typedef typename BPI::interface<BP>::first_argument_type
00177 first_argument_type;
00178 typedef typename BPI::interface<BP>::second_argument_type
00179 second_argument_type;
00180 CHECK_CONVERTIBILITY(value_type, first_argument_type);
00181 CHECK_CONVERTIBILITY(value_type, second_argument_type);
00182 if (equal(b, e)) {
00183 return true;
00184 }
00185 char c[sizeof(F)];
00186 F* n = 0;
00187 assign(n, copy_constructor(c, b));
00188 assert(0 != n);
00189 increment(*n);
00190 for (; !equal(*n, e); assign(b, *n), increment(*n)) {
00191 if (invoke_predicate(p, const_dereference(*n),
00192 const_dereference(b)))
00193 {
00194 return false;
00195 }
00196 }
00197 return true;
00198 }
00199
00200
00201
00202 #endif // INSTIGATE_STL_IS_SORTED_HPP