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_MERGE_HPP
00008 #define INSTIGATE_STL_MERGE_HPP
00009
00058
00059 #include "concept.hpp"
00060 #include "_copy.hpp"
00061
00062
00063 #include <generic/base.hpp>
00064
00065
00066
00067
00068 namespace instigate {
00069 namespace stl {
00070 template <typename I, typename I1, typename O>
00071 O merge(I b, I e, I1 f, I1 l, O r);
00072 template <typename I, typename I1, typename O, typename BP>
00073 O merge(I b, I e, I1 f, I1 l, O r, BP p);
00074 }
00075 }
00076
00130 template <typename I, typename I1, typename O>
00131 O instigate::stl::merge(I b, I e, I1 f, I1 l, O r)
00132 {
00133 namespace INC = instigate::stl::incrementable_iterator;
00134 namespace SP = instigate::stl::single_pass_iterator;
00135 namespace WR = instigate::stl::writable_iterator;
00136 namespace RI = instigate::stl::readable_iterator;
00137 namespace EQ = instigate::generic::equality_comparable;
00138 namespace LT = instigate::generic::less_than_comparable;
00139 CHECK(SP::requirements<I>);
00140 CHECK(RI::requirements<I>);
00141 CHECK(SP::requirements<I1>);
00142 CHECK(RI::requirements<I1>);
00143 CHECK(INC::requirements<O>);
00144 CHECK(WR::requirements<O>);
00145 typedef typename RI::interface<I>::value_type value_type1;
00146 typedef typename RI::interface<I1>::value_type value_type2;
00147 typedef typename RI::interface<O>::value_type value_type3;
00148 CHECK_SAME_TYPE(value_type1, value_type2);
00149 CHECK(LT::requirements<value_type1>);
00150 CHECK_CONVERTIBILITY(value_type1, value_type3);
00151 while (!equal(b, e) && !equal(f, l)) {
00152 if (less_than(const_dereference(f), const_dereference(b))) {
00153 dereference_assign(r, const_dereference(f));
00154 increment(f);
00155 } else {
00156 dereference_assign(r, const_dereference(b));
00157 increment(b);
00158 }
00159 increment(r);
00160 }
00161 return instigate::stl::copy(f, l, instigate::stl::copy(b, e, r));
00162 }
00163
00213 template <typename I, typename I1, typename O, typename BP>
00214 O instigate::stl::merge(I b, I e, I1 f, I1 l, O r, BP p)
00215 {
00216 namespace INC = instigate::stl::incrementable_iterator;
00217 namespace SP = instigate::stl::single_pass_iterator;
00218 namespace WR = instigate::stl::writable_iterator;
00219 namespace RI = instigate::stl::readable_iterator;
00220 namespace EQ = instigate::generic::equality_comparable;
00221 namespace LT = instigate::generic::less_than_comparable;
00222 namespace BI = instigate::stl::binary_predicate;
00223 CHECK(SP::requirements<I>);
00224 CHECK(RI::requirements<I>);
00225 CHECK(SP::requirements<I1>);
00226 CHECK(RI::requirements<I1>);
00227 CHECK(INC::requirements<O>);
00228 CHECK(WR::requirements<O>);
00229 CHECK(BI::requirements<BP>);
00230 typedef typename RI::interface<I>::value_type value_type1;
00231 typedef typename RI::interface<I1>::value_type value_type2;
00232 typedef typename RI::interface<O>::value_type value_type3;
00233 CHECK_SAME_TYPE(value_type1, value_type2);
00234 CHECK(LT::requirements<value_type1>);
00235 CHECK_CONVERTIBILITY(value_type1, value_type3);
00236 while (!equal(b, e) && !equal(f, l)) {
00237 if (invoke_predicate(p, const_dereference(f),
00238 const_dereference(b)))
00239 {
00240 dereference_assign(r, const_dereference(f));
00241 increment(f);
00242 } else {
00243 dereference_assign(r, const_dereference(b));
00244 increment(b);
00245 }
00246 increment(r);
00247 }
00248 return instigate::stl::copy(f, l, instigate::stl::copy(b, e, r));
00249 }
00250
00251
00252
00253 #endif // INSTIGATE_STL_MERGE_HPP