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_DIFFERENCE_HPP
00008 #define INSTIGATE_STL_SET_DIFFERENCE_HPP
00009
00059
00060 #include "concept.hpp"
00061 #include "_copy.hpp"
00062
00063
00064 #include <generic/base.hpp>
00065
00066
00067
00068
00069 namespace instigate {
00070 namespace stl {
00071 template <typename I, typename I1, typename O>
00072 O set_difference(I b, I e, I1 f, I1 l, O r);
00073 template <typename I, typename I1, typename O, typename BP>
00074 O set_difference(I b, I e, I1 f, I1 l, O r, BP p);
00075 }
00076 }
00077
00150 template <typename I, typename I1, typename O>
00151 O instigate::stl::set_difference(I b, I e, I1 f, I1 l, O r)
00152 {
00153 namespace SP = instigate::stl::single_pass_iterator;
00154 namespace RI = instigate::stl::readable_iterator;
00155 namespace EQ = instigate::generic::equality_comparable;
00156 namespace LT = instigate::generic::less_than_comparable;
00157 namespace INC = instigate::stl::incrementable_iterator;
00158 namespace WR = instigate::stl::writable_iterator;
00159 CHECK(SP::requirements<I>);
00160 CHECK(RI::requirements<I>);
00161 CHECK(SP::requirements<I1>);
00162 CHECK(RI::requirements<I1>);
00163 CHECK(INC::requirements<O>);
00164 CHECK(WR::requirements<O>);
00165 typedef typename RI::interface<I>::value_type value_type1;
00166 typedef typename RI::interface<I1>::value_type value_type2;
00167 CHECK_SAME_TYPE(value_type1, value_type2);
00168 CHECK_CONVERTIBILITY(value_type1, value_type2);
00169 CHECK(LT::requirements<value_type1>);
00170 while (!equal(b, e) && !equal(f, l)) {
00171 if (less_than(const_dereference(b), const_dereference(f))) {
00172 dereference_assign(r, const_dereference(b));
00173 increment(b);
00174 increment(r);
00175 }
00176 else if (less_than(const_dereference(f), const_dereference(b)))
00177 {
00178 increment(f);
00179 } else {
00180 increment(b);
00181 increment(f);
00182 }
00183 }
00184 return instigate::stl::copy(b, e, r);
00185 }
00186
00230 template <typename I, typename I1, typename O, typename BP>
00231 O instigate::stl::set_difference(I b, I e, I1 f, I1 l, O r, BP p)
00232 {
00233 namespace SP = instigate::stl::single_pass_iterator;
00234 namespace RI = instigate::stl::readable_iterator;
00235 namespace EQ = instigate::generic::equality_comparable;
00236 namespace LT = instigate::generic::less_than_comparable;
00237 namespace INC = instigate::stl::incrementable_iterator;
00238 namespace WR = instigate::stl::writable_iterator;
00239 namespace BPI = instigate::stl::binary_predicate;
00240 CHECK(SP::requirements<I>);
00241 CHECK(RI::requirements<I>);
00242 CHECK(SP::requirements<I1>);
00243 CHECK(RI::requirements<I1>);
00244 CHECK(INC::requirements<O>);
00245 CHECK(WR::requirements<O>);
00246 CHECK(BPI::requirements<BP>);
00247 typedef typename RI::interface<I>::value_type value_type1;
00248 typedef typename RI::interface<I1>::value_type value_type2;
00249 typedef typename WR::interface<O>::value_type value_type3;
00250 typedef typename BPI::interface<BP>::first_argument_type
00251 first_argument_type;
00252 typedef typename BPI::interface<BP>::second_argument_type
00253 second_argument_type;
00254 CHECK_SAME_TYPE(value_type1, value_type2);
00255 CHECK_CONVERTIBILITY(value_type1, value_type3);
00256 CHECK_CONVERTIBILITY(value_type2, value_type3);
00257 CHECK_CONVERTIBILITY(value_type1, first_argument_type);
00258 CHECK_CONVERTIBILITY(value_type2, second_argument_type);
00259 while (!equal(b, e) && !equal(f, l)) {
00260 if (invoke_predicate(p,
00261 const_dereference(b), const_dereference(f))) {
00262 dereference_assign(r, const_dereference(b));
00263 increment(b);
00264 increment(r);
00265 }
00266 else if (invoke_predicate(p,const_dereference(f),
00267 const_dereference(b)))
00268 {
00269 increment(f);
00270 }
00271 else {
00272 increment(b);
00273 increment(f);
00274 }
00275 }
00276 return instigate::stl::copy(b, e, r);
00277 }
00278
00279
00280
00281 #endif // INSTIGATE_STL_SET_DIFFERENCE_HPP