1
// (C) Copyright Thomas Becker 2005. Permission to copy, use, modify, sell and
2
// distribute this software is granted provided this copyright notice appears
3
// in all copies. This software is provided "as is" without express or implied
4
// warranty, and with no claim as to its suitability for any purpose.
9
// 27 Dec 2006 (Thomas Becker) Created
16
// Enable rudimentary memory tracking under Win32.
17
#define _CRTDBG_MAP_ALLOC
21
// Disable stupid warning about what Microsoft thinks is deprecated
22
#pragma warning( disable : 4996 )
26
#include <mlib/any_iterator/detail/any_iterator_wrapper.hpp>
29
#define ASSERT_RETURN_FALSE( b ) if( ! (b) ){ return false; }
31
using namespace IteratorTypeErasure;
33
bool test_any_iterator_wrapper()
36
std::vector<int> vect_of_ints;
37
vect_of_ints.push_back(42);
38
vect_of_ints.push_back(43);
39
vect_of_ints.push_back(47);
41
//////////////////////////////////////////////////////////////////////
45
/////////////////////////////////////////////////////////////////////
47
detail::any_iterator_wrapper<
48
std::vector<int>::const_iterator,
50
boost::incrementable_traversal_tag,
53
> default_constructed_const_incrementable_wrapper;
55
detail::any_iterator_wrapper<
56
std::vector<int>::const_iterator,
58
boost::incrementable_traversal_tag,
61
> const_incrementable_wrapper(vect_of_ints.begin());
63
ASSERT_RETURN_FALSE( 42 == const_incrementable_wrapper.dereference() );
64
const_incrementable_wrapper.increment();
65
ASSERT_RETURN_FALSE( 43 == const_incrementable_wrapper.dereference() );
67
detail::any_iterator_abstract_base<
69
boost::incrementable_traversal_tag,
72
>* const_incrementable_wrapper_clone = const_incrementable_wrapper.clone();
74
ASSERT_RETURN_FALSE( 43 == const_incrementable_wrapper_clone->dereference() );
76
delete const_incrementable_wrapper_clone;
78
detail::any_iterator_wrapper<
79
std::vector<int>::iterator,
81
boost::incrementable_traversal_tag,
84
> incrementable_wrapper(vect_of_ints.begin());
86
incrementable_wrapper.dereference() = 4711;
87
ASSERT_RETURN_FALSE( 4711 == incrementable_wrapper.dereference() );
88
incrementable_wrapper.dereference() = 42;
90
const_incrementable_wrapper_clone = incrementable_wrapper.make_const_clone_with_const_value_type();
91
ASSERT_RETURN_FALSE( 42 == const_incrementable_wrapper_clone->dereference() );
93
detail::any_iterator_abstract_base<
95
boost::incrementable_traversal_tag,
98
>* const_incrementable_wrapper_clone_with_non_const_value_type = incrementable_wrapper.make_const_clone_with_non_const_value_type();
99
ASSERT_RETURN_FALSE( 42 == const_incrementable_wrapper_clone_with_non_const_value_type->dereference() );
101
delete const_incrementable_wrapper_clone;
102
delete const_incrementable_wrapper_clone_with_non_const_value_type;
104
//////////////////////////////////////////////////////////////////////
108
/////////////////////////////////////////////////////////////////////
110
detail::any_iterator_wrapper<
111
std::vector<int>::const_iterator,
113
boost::single_pass_traversal_tag,
116
> default_constructed_single_pass_wrapper;
118
detail::any_iterator_wrapper<
119
std::vector<int>::const_iterator,
121
boost::single_pass_traversal_tag,
124
> const_single_pass_wrapper(vect_of_ints.begin());
126
ASSERT_RETURN_FALSE( 42 == const_single_pass_wrapper.dereference() );
127
const_single_pass_wrapper.increment();
128
ASSERT_RETURN_FALSE( 43 == const_single_pass_wrapper.dereference() );
130
detail::any_iterator_abstract_base<
132
boost::single_pass_traversal_tag,
135
>* const_single_pass_wrapper_clone = const_single_pass_wrapper.clone();
137
ASSERT_RETURN_FALSE( 43 == const_single_pass_wrapper_clone->dereference() );
139
delete const_single_pass_wrapper_clone;
141
detail::any_iterator_wrapper<
142
std::vector<int>::iterator,
144
boost::single_pass_traversal_tag,
147
> single_pass_wrapper(vect_of_ints.begin());
149
single_pass_wrapper.dereference() = 4711;
150
ASSERT_RETURN_FALSE( 4711 == single_pass_wrapper.dereference() );
151
single_pass_wrapper.dereference() = 42;
153
const_single_pass_wrapper_clone = single_pass_wrapper.make_const_clone_with_const_value_type();
154
ASSERT_RETURN_FALSE( 42 == const_single_pass_wrapper_clone->dereference() );
156
detail::any_iterator_abstract_base<
158
boost::single_pass_traversal_tag,
161
>* const_single_pass_wrapper_clone_with_non_const_value_type = const_single_pass_wrapper.make_const_clone_with_non_const_value_type();
162
ASSERT_RETURN_FALSE( 43 == const_single_pass_wrapper_clone_with_non_const_value_type->dereference() );
164
delete const_single_pass_wrapper_clone;
165
delete const_single_pass_wrapper_clone_with_non_const_value_type;
167
//////////////////////////////////////////////////////////////////////
171
/////////////////////////////////////////////////////////////////////
173
detail::any_iterator_wrapper<
174
std::vector<int>::const_iterator,
176
boost::forward_traversal_tag,
179
> default_constructed_forward_wrapper;
181
detail::any_iterator_wrapper<
182
std::vector<int>::const_iterator,
184
boost::forward_traversal_tag,
187
> const_forward_wrapper(vect_of_ints.begin());
189
ASSERT_RETURN_FALSE( 42 == const_forward_wrapper.dereference() );
190
const_forward_wrapper.increment();
191
ASSERT_RETURN_FALSE( 43 == const_forward_wrapper.dereference() );
193
detail::any_iterator_abstract_base<
195
boost::forward_traversal_tag,
198
>* const_forward_wrapper_clone = const_forward_wrapper.clone();
200
ASSERT_RETURN_FALSE( 43 == const_forward_wrapper_clone->dereference() );
202
ASSERT_RETURN_FALSE( const_forward_wrapper.equal(*const_forward_wrapper_clone) );
203
const_forward_wrapper_clone->increment();
204
ASSERT_RETURN_FALSE( ! const_forward_wrapper.equal(*const_forward_wrapper_clone) );
206
delete const_forward_wrapper_clone;
208
detail::any_iterator_wrapper<
209
std::vector<int>::iterator,
211
boost::forward_traversal_tag,
214
> forward_wrapper(vect_of_ints.begin());
216
forward_wrapper.dereference() = 4711;
217
ASSERT_RETURN_FALSE( 4711 == forward_wrapper.dereference() );
218
forward_wrapper.dereference() = 42;
220
const_forward_wrapper_clone = forward_wrapper.make_const_clone_with_const_value_type();
221
ASSERT_RETURN_FALSE( 42 == const_forward_wrapper_clone->dereference() );
222
detail::any_iterator_abstract_base<
224
boost::forward_traversal_tag,
227
>* const_forward_wrapper_clone_with_non_const_value_type = const_forward_wrapper.make_const_clone_with_non_const_value_type();
228
ASSERT_RETURN_FALSE( 43 == const_forward_wrapper_clone_with_non_const_value_type->dereference() );
230
delete const_forward_wrapper_clone;
231
delete const_forward_wrapper_clone_with_non_const_value_type;
233
//////////////////////////////////////////////////////////////////////
237
/////////////////////////////////////////////////////////////////////
239
detail::any_iterator_wrapper<
240
std::vector<int>::const_iterator,
242
boost::bidirectional_traversal_tag,
245
> default_constructed_bidirectional_wrapper;
247
detail::any_iterator_wrapper<
248
std::vector<int>::const_iterator,
250
boost::bidirectional_traversal_tag,
253
> const_bidirectional_wrapper(vect_of_ints.begin());
255
ASSERT_RETURN_FALSE( 42 == const_bidirectional_wrapper.dereference() );
256
const_bidirectional_wrapper.increment();
257
ASSERT_RETURN_FALSE( 43 == const_bidirectional_wrapper.dereference() );
258
const_bidirectional_wrapper.decrement();
259
ASSERT_RETURN_FALSE( 42 == const_bidirectional_wrapper.dereference() );
261
detail::any_iterator_abstract_base<
263
boost::bidirectional_traversal_tag,
266
>* const_bidirectional_wrapper_clone = const_bidirectional_wrapper.clone();
268
ASSERT_RETURN_FALSE( 42 == const_bidirectional_wrapper_clone->dereference() );
270
ASSERT_RETURN_FALSE( const_bidirectional_wrapper.equal(*const_bidirectional_wrapper_clone) );
271
const_bidirectional_wrapper_clone->increment();
272
ASSERT_RETURN_FALSE( ! const_bidirectional_wrapper.equal(*const_bidirectional_wrapper_clone) );
274
delete const_bidirectional_wrapper_clone;
276
detail::any_iterator_wrapper<
277
std::vector<int>::iterator,
279
boost::bidirectional_traversal_tag,
282
> bidirectional_wrapper(vect_of_ints.begin());
284
bidirectional_wrapper.dereference() = 4711;
285
ASSERT_RETURN_FALSE( 4711 == bidirectional_wrapper.dereference() );
286
bidirectional_wrapper.dereference() = 42;
288
const_bidirectional_wrapper_clone = bidirectional_wrapper.make_const_clone_with_const_value_type();
289
ASSERT_RETURN_FALSE( 42 == const_bidirectional_wrapper_clone->dereference() );
291
detail::any_iterator_abstract_base<
293
boost::bidirectional_traversal_tag,
296
>* const_bidirectional_wrapper_clone_with_non_const_value_type = const_bidirectional_wrapper.make_const_clone_with_non_const_value_type();
297
ASSERT_RETURN_FALSE( 42 == const_bidirectional_wrapper_clone_with_non_const_value_type->dereference() );
299
delete const_bidirectional_wrapper_clone;
300
delete const_bidirectional_wrapper_clone_with_non_const_value_type;
302
//////////////////////////////////////////////////////////////////////
306
/////////////////////////////////////////////////////////////////////
308
detail::any_iterator_wrapper<
309
std::vector<int>::const_iterator,
311
boost::random_access_traversal_tag,
314
> default_constructed_random_access_wrapper;
316
detail::any_iterator_wrapper<
317
std::vector<int>::const_iterator,
319
boost::random_access_traversal_tag,
322
> const_random_access_wrapper(vect_of_ints.begin());
324
ASSERT_RETURN_FALSE( 42 == const_random_access_wrapper.dereference() );
325
const_random_access_wrapper.increment();
326
ASSERT_RETURN_FALSE( 43 == const_random_access_wrapper.dereference() );
327
const_random_access_wrapper.decrement();
328
ASSERT_RETURN_FALSE( 42 == const_random_access_wrapper.dereference() );
330
const_random_access_wrapper.advance(2);
331
ASSERT_RETURN_FALSE( 47 == const_random_access_wrapper.dereference() );
332
const_random_access_wrapper.advance(-2);
333
ASSERT_RETURN_FALSE( 42 == const_random_access_wrapper.dereference() );
335
detail::any_iterator_wrapper<
336
std::vector<int>::const_iterator,
338
boost::random_access_traversal_tag,
341
> other_const_random_access_wrapper = const_random_access_wrapper;
342
other_const_random_access_wrapper.advance(3);
343
ASSERT_RETURN_FALSE( 3 == const_random_access_wrapper.distance_to(other_const_random_access_wrapper) );
345
detail::any_iterator_abstract_base<
347
boost::random_access_traversal_tag,
350
>* const_random_access_wrapper_clone = const_random_access_wrapper.clone();
352
ASSERT_RETURN_FALSE( 42 == const_random_access_wrapper_clone->dereference() );
354
ASSERT_RETURN_FALSE( const_random_access_wrapper.equal(*const_random_access_wrapper_clone) );
355
const_random_access_wrapper_clone->increment();
356
ASSERT_RETURN_FALSE( ! const_random_access_wrapper.equal(*const_random_access_wrapper_clone) );
358
delete const_random_access_wrapper_clone;
360
detail::any_iterator_wrapper<
361
std::vector<int>::iterator,
363
boost::random_access_traversal_tag,
366
> random_access_wrapper(vect_of_ints.begin());
368
random_access_wrapper.dereference() = 4711;
369
ASSERT_RETURN_FALSE( 4711 == random_access_wrapper.dereference() );
370
random_access_wrapper.dereference() = 42;
372
const_random_access_wrapper_clone = random_access_wrapper.make_const_clone_with_const_value_type();
373
ASSERT_RETURN_FALSE( 42 == const_random_access_wrapper_clone->dereference() );
374
detail::any_iterator_abstract_base<
376
boost::random_access_traversal_tag,
379
>* const_random_access_wrapper_clone_with_non_const_value_type = const_random_access_wrapper.make_const_clone_with_non_const_value_type();
380
ASSERT_RETURN_FALSE( 42 == const_random_access_wrapper_clone_with_non_const_value_type->dereference() );
382
delete const_random_access_wrapper_clone;
383
delete const_random_access_wrapper_clone_with_non_const_value_type;