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_SET_UNION_HPP
00008 #define INSTIGATE_STL_SET_UNION_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 set_union(I b, I e, I1 f, I1 l, O r);
00072 template <typename I, typename I1, typename O, typename BP>
00073 O set_union(I b, I e, I1 f, I1 l, O r, BP p);
00074 }
00075 }
00076
00143 template <typename I, typename I1, typename O>
00144 O instigate::stl::set_union(I b, I e, I1 f, I1 l, O r)
00145 {
00146 namespace SP = instigate::stl::single_pass_iterator;
00147 namespace RI = instigate::stl::readable_iterator;
00148 namespace EQ = instigate::generic::equality_comparable;
00149 namespace LT = instigate::generic::less_than_comparable;
00150 namespace INC = instigate::stl::incrementable_iterator;
00151 namespace WR = instigate::stl::writable_iterator;
00152 CHECK(SP::requirements<I>);
00153 CHECK(RI::requirements<I>);
00154 CHECK(SP::requirements<I1>);
00155 CHECK(RI::requirements<I1>);
00156 CHECK(INC::requirements<O>);
00157 CHECK(WR::requirements<O>);
00158 typedef typename RI::interface<I>::value_type value_type1;
00159 typedef typename RI::interface<I1>::value_type value_type2;
00160 CHECK_SAME_TYPE(value_type1, value_type2);
00161 CHECK_CONVERTIBILITY(value_type1, value_type2);
00162 CHECK(LT::requirements<value_type1>);
00163 while (!equal(b, e) && !equal(f, l)) {
00164 if (less_than(const_dereference(b), const_dereference(f))) {
00165 dereference_assign(r, const_dereference(b));
00166 increment(b);
00167 }
00168 else if (less_than(const_dereference(f),const_dereference(b))){
00169 dereference_assign(r, const_dereference(f));
00170 increment(f);
00171 } else {
00172 dereference_assign(r, const_dereference(b));
00173 increment(b);
00174 increment(f);
00175 }
00176 increment(r);
00177 }
00178 return instigate::stl::copy(f, l, instigate::stl::copy(b, e, r));
00179 }
00180
00238 template <typename I, typename I1, typename O, typename BP>
00239 O instigate::stl::set_union(I b, I e, I1 f, I1 l, O r, BP p)
00240 {
00241 namespace SP = instigate::stl::single_pass_iterator;
00242 namespace RI = instigate::stl::readable_iterator;
00243 namespace EQ = instigate::generic::equality_comparable;
00244 namespace LT = instigate::generic::less_than_comparable;
00245 namespace INC = instigate::stl::incrementable_iterator;
00246 namespace WR = instigate::stl::writable_iterator;
00247 namespace BPI = instigate::stl::binary_predicate;
00248 CHECK(SP::requirements<I>);
00249 CHECK(RI::requirements<I>);
00250 CHECK(SP::requirements<I1>);
00251 CHECK(RI::requirements<I1>);
00252 CHECK(INC::requirements<O>);
00253 CHECK(WR::requirements<O>);
00254 CHECK(BPI::requirements<BP>);
00255 typedef typename RI::interface<I>::value_type value_type1;
00256 typedef typename RI::interface<I1>::value_type value_type2;
00257 typedef typename WR::interface<O>::value_type value_type3;
00258 typedef typename BPI::interface<BP>::first_argument_type
00259 first_argument_type;
00260 typedef typename BPI::interface<BP>::second_argument_type
00261 second_argument_type;
00262 CHECK_SAME_TYPE(value_type1, value_type2);
00263 CHECK_CONVERTIBILITY(value_type1, value_type3);
00264 CHECK_CONVERTIBILITY(value_type2, value_type3);
00265 CHECK_CONVERTIBILITY(value_type1, first_argument_type);
00266 CHECK_CONVERTIBILITY(value_type2, second_argument_type);
00267 while (!equal(b, e) && !equal(f, l)) {
00268 if (invoke_predicate(p, const_dereference(b),
00269 const_dereference(f)))
00270 {
00271 dereference_assign(r, const_dereference(b));
00272 increment(b);
00273 } else if (invoke_predicate(p, const_dereference(f),
00274 const_dereference(b)))
00275 {
00276 dereference_assign(r, const_dereference(f));
00277 increment(f);
00278 } else {
00279 dereference_assign(r, const_dereference(b));
00280 increment(b);
00281 increment(f);
00282 }
00283 increment(r);
00284 }
00285 return instigate::stl::copy(f, l, instigate::stl::copy(b, e, r));
00286 }
00287
00288
00289
00290 #endif // INSTIGATE_STL_SET_UNION_HPP
00291