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_BASIS_HPP
00008 #define INSTIGATE_STL_BASIS_HPP
00009
00057
00058 #include "concept.hpp"
00059 #include "_destructible_iterator.hpp"
00060
00061
00062 #include <generic/base.hpp>
00063
00064
00065
00066
00067
00069 namespace instigate {
00071 namespace stl {
00072 template <typename T>
00073 inline void assign(T&, const T&);
00074
00075 template <typename T>
00076 inline T* copy_constructor(char* const, const T&);
00077
00078 template <typename T>
00079 inline bool equal(const T&, const T&);
00080
00081 template <typename T>
00082 inline T* initialize(char* const);
00083
00084 template <typename T>
00085 inline void increment(T&);
00086
00087 template <typename T>
00088 inline const typename instigate::stl::readable_iterator::
00089 interface<T>::value_type& const_dereference(const T&);
00090
00091 template <typename T>
00092 inline typename instigate::stl::lvalue_iterator::
00093 interface<T>::value_type& dereference(const T&);
00094
00095 template <typename T>
00096 inline void dereference_assign(T, const typename
00097 stl::writable_iterator::interface<T>::value_type&);
00098
00099 template <typename T>
00100 inline void dereference_assign(std::ostream_iterator<T>,
00101 const T&);
00102
00103 template <typename T>
00104 inline bool less_than(const T&, const T&);
00105
00106 template <typename T>
00107 inline void decrement(T&);
00108
00109 template <typename G>
00110 inline typename instigate::stl::generator::interface<G>::
00111 result_type invoke(const G&);
00112
00113 template <typename UF>
00114 inline typename instigate::stl::unary_function::interface<UF>::
00115 result_type invoke(const UF&, typename instigate::stl::
00116 unary_function::interface<UF>::argument_type);
00117
00118 template <typename BF>
00119 inline typename instigate::stl::binary_function::interface<BF>::
00120 result_type invoke(const BF&,
00121 typename instigate::stl::binary_function::
00122 interface<BF>::first_argument_type,
00123 typename instigate::stl::binary_function::
00124 interface<BF>::second_argument_type);
00125
00126 template <typename UP>
00127 inline bool invoke_predicate(const UP&, typename instigate::stl::
00128 unary_predicate::interface<UP>::argument_type);
00129
00130 template <typename BP>
00131 inline bool invoke_predicate(const BP&,
00132 typename instigate::stl::binary_predicate::
00133 interface<BP>::first_argument_type,
00134 typename instigate::stl::binary_predicate::
00135 interface<BP>::second_argument_type);
00136
00137 template <typename TF>
00138 inline typename instigate::stl::ternary_function::
00139 interface<TF>::result_type invoke(const TF&,
00140 typename instigate::stl::ternary_function::
00141 interface<TF>::first_argument_type,
00142 typename instigate::stl::ternary_function::
00143 interface<TF>::second_argument_type,
00144 typename instigate::stl::ternary_function::
00145 interface<TF>::third_argument_type);
00146 template <typename T>
00147 void destroy(T b, T e);
00148 namespace implementation {
00149 template <typename T>
00150 void destroy_disp(T b, T e, instigate::stl::false_type);
00151 template <typename T>
00152 void destroy_disp(T b, T e, instigate::stl::true_type);
00153 }
00154 }
00155 }
00156
00157
00162 template <typename T>
00163 static void instigate::stl::implementation::
00164 destroy_disp(T b, T e, instigate::stl::false_type)
00165 {
00166 for ( ; b != e; ++b){
00167 instigate::stl::destructible_iterator::interface<T>::
00168 destroy(instigate::stl::lvalue_iterator::interface<T>::
00169 dereference(b));
00170 }
00171 }
00172
00177 template <typename T>
00178 static void instigate::stl::implementation::
00179 destroy_disp(T, T, instigate::stl::true_type)
00180 {
00181 }
00182
00189 template <typename T>
00190 static void instigate::stl::destroy(T b, T e)
00191 {
00192 namespace RI = instigate::stl::readable_iterator;
00193 typename instigate::stl::unary_type_traits<T>::
00194 has_trivial_destructor d;
00195 instigate::stl::implementation::destroy_disp(b, e, d);
00196 }
00206 template <typename T>
00207 inline void instigate::stl::assign(T& a, const T& b)
00208 {
00209 CHECK(instigate::generic::assignable::requirements<T>);
00210 instigate::generic::assignable::interface<T>::assign(a, b);
00211 }
00212
00224 template <typename T>
00225 inline T* instigate::stl::copy_constructor(char* const ptr, const T& ob)
00226 {
00227 assert(0 != ptr);
00228 CHECK(instigate::generic::assignable::requirements<T>);
00229 T* t = instigate::generic::assignable::interface<T>
00230 ::copy_constructor(ptr, ob);
00231 assert(0 != t);
00232 return t;
00233 }
00234
00249 template <typename T>
00250 inline bool instigate::stl::equal(const T& a, const T& b)
00251 {
00252 CHECK(instigate::generic::equality_comparable::requirements<T>);
00253 return instigate::generic::equality_comparable::
00254 interface<T>::equal(a, b);
00255 }
00256
00267 template <typename T>
00268 inline T* instigate::stl::initialize(char* const p)
00269 {
00270 assert(0 != p);
00271 CHECK(instigate::generic::default_constructible::requirements<T>);
00272 return instigate::generic::default_constructible::interface<T>
00273 ::initialize(p);
00274 }
00275
00284 template <typename T>
00285 inline void instigate::stl::increment(T& a)
00286 {
00287 CHECK(instigate::stl::incrementable_iterator::requirements<T>);
00288 instigate::stl::incrementable_iterator::interface<T>::increment(a);
00289 }
00290
00302 template <typename T>
00303 inline const typename instigate::stl::readable_iterator::interface<T>::
00304 value_type& instigate::stl::const_dereference(const T& a)
00305 {
00306 CHECK(instigate::stl::readable_iterator::requirements<T>);
00307 return instigate::stl::readable_iterator::interface<T>::
00308 const_dereference(a);
00309 }
00310
00320 template <typename T>
00321 inline void instigate::stl::dereference_assign(T a, const typename
00322 stl::writable_iterator::interface<T>::value_type& b)
00323 {
00324 CHECK(instigate::stl::writable_iterator::requirements<T>);
00325 instigate::stl::writable_iterator::interface<T>::
00326 dereference_assign(a, b);
00327 }
00328
00336 template <typename T>
00337 inline void instigate::stl::dereference_assign(std::ostream_iterator<T> a,
00338 const T& b)
00339 {
00340 CHECK(stl::writable_iterator::requirements<std::ostream_iterator<T> >);
00341 instigate::stl::writable_iterator::
00342 interface<std::ostream_iterator<T> >::dereference_assign(a, b);
00343 }
00344
00355 template <typename T>
00356 inline typename instigate::stl::lvalue_iterator::interface<T>::value_type&
00357 instigate::stl::dereference(const T& a)
00358 {
00359 CHECK(instigate::stl::lvalue_iterator::requirements<T>);
00360 return instigate::stl::lvalue_iterator::interface<T>::dereference(a);
00361 }
00362
00374 template <typename T>
00375 inline bool instigate::stl::less_than(const T& a, const T& b)
00376 {
00377 CHECK(instigate::generic::less_than_comparable::requirements<T>);
00378 return instigate::generic::less_than_comparable::interface<T>
00379 ::less_than(a, b);
00380 }
00381
00390 template <typename T>
00391 inline void instigate::stl::decrement(T& a)
00392 {
00393 CHECK(instigate::stl::bidirectional_iterator::requirements<T>);
00394 instigate::stl::bidirectional_iterator::interface<T>::decrement(a);
00395 }
00396
00407 template <typename G>
00408 inline typename instigate::stl::generator::interface<G>::result_type
00409 instigate::stl::invoke(const G& g)
00410 {
00411 CHECK(instigate::stl::generator::requirements<G>);
00412 return instigate::stl::generator::interface<G>::invoke(g);
00413 }
00414
00426 template <typename UF>
00427 inline typename instigate::stl::unary_function::interface<UF>::result_type
00428 instigate::stl::invoke(const UF& f, typename instigate::stl::
00429 unary_function::interface<UF>::argument_type a)
00430 {
00431 CHECK(instigate::stl::unary_function::requirements<UF>);
00432 return instigate::stl::unary_function::interface<UF>::invoke(f, a);
00433 }
00434
00446 template <typename UP>
00447 inline bool instigate::stl::invoke_predicate(const UP& f,
00448 typename instigate::stl::unary_predicate::
00449 interface<UP>::argument_type a)
00450 {
00451 CHECK(instigate::stl::unary_predicate::requirements<UP>);
00452 return instigate::stl::unary_predicate::interface<UP>::invoke(f, a);
00453 }
00454
00467 template <typename BF>
00468 inline typename instigate::stl::binary_function::interface<BF>::result_type
00469 instigate::stl::invoke(const BF& f,
00470 typename instigate::stl::binary_function::interface<BF>::
00471 first_argument_type a1,
00472 typename instigate::stl::binary_function::interface<BF>::
00473 second_argument_type a2)
00474 {
00475 CHECK(instigate::stl::binary_function::requirements<BF>);
00476 return instigate::stl::binary_function::interface<BF>::
00477 invoke(f, a1, a2);
00478 }
00479
00492 template <typename BP>
00493 inline bool instigate::stl::invoke_predicate(const BP& f,
00494 typename instigate::stl::binary_predicate::
00495 interface<BP>::first_argument_type a1,
00496 typename instigate::stl::binary_predicate::
00497 interface<BP>::second_argument_type a2)
00498 {
00499 CHECK(instigate::stl::binary_predicate::requirements<BP>);
00500 return instigate::stl::binary_predicate::interface<BP>::
00501 invoke(f, a1, a2);
00502 }
00503
00517 template <typename TF>
00518 inline typename instigate::stl::ternary_function::interface<TF>::result_type
00519 instigate::stl::invoke(const TF& f,
00520 typename instigate::stl::ternary_function::
00521 interface<TF>::first_argument_type a1,
00522 typename instigate::stl::ternary_function::
00523 interface<TF>::second_argument_type a2,
00524 typename instigate::stl::ternary_function::
00525 interface<TF>::third_argument_type a3)
00526 {
00527 CHECK(instigate::stl::ternary_function::requirements<TF>);
00528 return instigate::stl::ternary_function::interface<TF>::
00529 invoke(f, a1, a2, a3);
00530 }
00531
00532
00533
00534 #endif // INSTIGATE_STL_BASIS_HPP