00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #ifndef STLSOFT_INCL_H_STLSOFT
00070 # include "stlsoft.h"
00071 #endif
00072
00073 #if defined(__STLSOFT_COMPILER_IS_MSVC) && \
00074 _MSC_VER < 1200
00075 # error stlsoft_sequence_container_veneer.h is not compatible with Visual C++ 5.0 or earlier
00076 #endif
00077
00078 #ifdef STLSOFT_UNITTEST
00079 # include <algorithm>
00080 # include <list>
00081 # include <vector>
00082 #endif
00083
00084
00085
00086
00087
00088 #ifndef _STLSOFT_NO_NAMESPACE
00089 namespace stlsoft
00090 {
00091 #endif
00092
00093
00094
00095
00096
00101 template< ss_typename_param_k T
00102 , ss_typename_param_k F
00103 >
00104 class sequence_container_veneer
00105 : public T
00106 {
00107 public:
00109 typedef T container_type;
00111 typedef F element_destruction_function_type;
00113 typedef sequence_container_veneer<T, F> class_type;
00114 private:
00115 typedef T parent_class_type;
00116 public:
00118 typedef ss_typename_type_k parent_class_type::allocator_type allocator_type;
00120 typedef ss_typename_type_k parent_class_type::size_type size_type;
00121
00122
00123 public:
00124 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00125
00126 sequence_container_veneer()
00127 {}
00128
00130 sequence_container_veneer(class_type const &rhs)
00131 : parent_class_type(rhs)
00132 {}
00133
00134 #if !defined(__STLSOFT_COMPILER_IS_DMC)
00135
00136 ss_explicit_k sequence_container_veneer(allocator_type const &a)
00137 : parent_class_type(a)
00138 {}
00140 template <ss_typename_param_k I>
00141 sequence_container_veneer(I i1, I i2)
00142 : parent_class_type(i1, i2)
00143 {}
00145 template <ss_typename_param_k I>
00146 sequence_container_veneer(I i1, I i2, allocator_type const &a)
00147 : parent_class_type(i1, i2, a)
00148 {}
00150 template <ss_typename_param_k V>
00151 sequence_container_veneer(size_type n, V v)
00152 : parent_class_type(n, v)
00153 {}
00155 template <ss_typename_param_k V>
00156 sequence_container_veneer(size_type n, V v, allocator_type const &a)
00157 : parent_class_type(n, v, a)
00158 {}
00159 #else
00160 template <ss_typename_param_k N1>
00161 ss_explicit_k sequence_container_veneer(N1 n1)
00162 : parent_class_type(n1)
00163 {}
00164 template< ss_typename_param_k N1
00165 , ss_typename_param_k N2
00166 >
00167 sequence_container_veneer(N1 n1, N2 n2)
00168 : parent_class_type(n1, n2)
00169 {}
00170 template< ss_typename_param_k N1
00171 , ss_typename_param_k N2
00172 , ss_typename_param_k N3
00173 >
00174 sequence_container_veneer(N1 n1, N2 n2, N3 n3)
00175 : parent_class_type(n1, n2, n3)
00176 {}
00177 template< ss_typename_param_k N1
00178 , ss_typename_param_k N2
00179 , ss_typename_param_k N3
00180 , ss_typename_param_k N4
00181 >
00182 sequence_container_veneer(N1 n1, N2 n2, N3 n3, N4 n4)
00183 : parent_class_type(n1, n2, n3, n4)
00184 {}
00185 template< ss_typename_param_k N1
00186 , ss_typename_param_k N2
00187 , ss_typename_param_k N3
00188 , ss_typename_param_k N4
00189 , ss_typename_param_k N5
00190 >
00191 sequence_container_veneer(N1 n1, N2 n2, N3 n3, N4 n4, N5 n5)
00192 : parent_class_type(n1, n2, n3, n4, n5)
00193 {}
00194 #endif
00195 #endif
00196
00199 ~sequence_container_veneer() stlsoft_throw_0()
00200 {
00201
00202
00203 parent_class_type *this_ = this;
00204
00205 ss_typename_type_k container_type::iterator b = this_->begin();
00206 ss_typename_type_k container_type::iterator e = this_->end();
00207
00208 for(; b != e; ++b)
00209 {
00210 element_destruction_function_type()(*b);
00211 }
00212 }
00213
00220 class_type &operator =(class_type const &rhs)
00221 {
00222 parent_class_type::operator =(rhs);
00223
00224 return *this;
00225 }
00226
00227 protected:
00230 void *operator new(size_t )
00231 {
00232 return 0;
00233 }
00236 void operator delete(void *)
00237 {}
00238 };
00239
00241
00242
00243 #ifdef STLSOFT_UNITTEST
00244
00245 namespace unittest
00246 {
00247 # if !defined(__STLSOFT_COMPILER_IS_MSVC) || \
00248 _MSC_VER >= 1200
00249 namespace
00250 {
00251 #endif
00252 struct null_int_functor
00253 {
00254 public:
00255 void operator ()(int const &)
00256 {}
00257 };
00258 # if !defined(__STLSOFT_COMPILER_IS_MSVC) || \
00259 _MSC_VER >= 1200
00260 }
00261 #endif
00262
00263 ss_bool_t test_stlsoft_sequence_container_veneer(unittest_reporter *r)
00264 {
00265 ss_bool_t bSuccess = true;
00266
00267 unittest_initialiser init(r, "STLSoft", "sequence_container_veneer", __FILE__);
00268
00269 typedef stlsoft_ns_qual_std(list)<int> list_t;
00270 typedef stlsoft_ns_qual_std(vector)<int> vector_t;
00271
00272 sequence_container_veneer<list_t, null_int_functor> l;
00273 sequence_container_veneer<vector_t, null_int_functor> v;
00274 int i;
00275 int total;
00276
00277 for(i = 0, total = 0; i < 10; ++i)
00278 {
00279 l.push_front(i);
00280 v.push_back(i);
00281
00282 total += i;
00283 }
00284
00285 if(stlsoft_ns_qual_std(accumulate)(l.begin(), l.end(), static_cast<long>(0)) != total)
00286 {
00287 r->report("sequence_container_veneer<list> contents (forward iteration) test failed ", __LINE__);
00288 bSuccess = false;
00289 }
00290
00291 #if defined(__STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00292 if(stlsoft_ns_qual_std(accumulate)(l.rbegin(), l.rend(), static_cast<long>(0)) != total)
00293 {
00294 r->report("sequence_container_veneer<list> contents (forward iteration) test failed ", __LINE__);
00295 bSuccess = false;
00296 }
00297 #endif
00298
00299 if(stlsoft_ns_qual_std(accumulate)(v.begin(), v.end(), static_cast<long>(0)) != total)
00300 {
00301 r->report("sequence_container_veneer<vector> contents (forward iteration) test failed ", __LINE__);
00302 bSuccess = false;
00303 }
00304
00305 #if defined(__STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00306 if(stlsoft_ns_qual_std(accumulate)(v.rbegin(), v.rend(), static_cast<long>(0)) != total)
00307 {
00308 r->report("sequence_container_veneer<vector> contents (forward iteration) test failed ", __LINE__);
00309 bSuccess = false;
00310 }
00311 #endif
00312
00313 return bSuccess;
00314 }
00315
00316 unittest_registrar unittest_stlsoft_sequence_container_veneer(test_stlsoft_sequence_container_veneer);
00317
00318 }
00319
00320 #endif
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332