38 #include <boost/lexical_cast.hpp> 47 using LERR_(ITER_EXHAUST);
48 using boost::lexical_cast;
68 data_.push_back(num--);
71 typedef vector<int>::iterator sourceIter;
74 typedef vector<int>::const_iterator const_sourceIter;
77 iterator begin() {
return iterator(data_.begin(),data_.end()); }
78 iterator end() {
return iterator(); }
79 const_iterator begin()
const {
return const_iterator(data_.begin(),data_.end()); }
80 const_iterator end()
const {
return const_iterator(); }
94 typedef vector<int *> _Vec;
98 static void killIt (
int *it) {
delete it; }
105 for (uint i=0; i<count; ++i)
106 numberz_[i] =
new int(i);
111 for_each (numberz_, killIt);
124 iterator begin () {
return iterator (
this, numberz_.begin()); }
125 const_iterator begin ()
const {
return const_iterator (
this, numberz_.begin()); }
126 ref_iterator begin_ref () {
return ref_iterator (begin()); }
127 const_ref_iter begin_ref ()
const {
return const_ref_iter (begin()); }
129 iterator end () {
return iterator(); }
130 const_iterator end ()
const {
return const_iterator(); }
132 size_t size()
const {
return numberz_.size(); }
166 if ((pos != ITER()) && (pos != src->numberz_.end()))
199 if (0 < arg.size()) NUM_ELMS = lexical_cast<uint> (arg[1]);
201 useSimpleWrappedContainer ();
205 TestContainer testElms (NUM_ELMS);
206 simpleUsage (testElms);
208 iterTypeVariations (testElms);
209 verifyComparisons (testElms);
210 exposeDataAddresses();
219 const int N = NUM_ELMS;
227 CHECK (sum == (N-1)*N / 2);
253 vector<int> iVec (NUM_ELMS);
254 for (uint i=0; i < NUM_ELMS; ++i)
257 typedef vector<int>::iterator I;
260 Range range (iVec.begin(), iVec.end());
261 CHECK (!isnil (range) || !NUM_ELMS);
266 cout <<
"::" << *range;
271 CHECK (isnil (range));
272 CHECK (range == Range());
282 for_each (elms, showIntP);
286 static void showIntP (
int* elm) { cout <<
"::" << *elm; }
287 static void showInt (
int elm) { cout <<
"::" << elm; }
292 useSimpleWrappedContainer ()
294 WrappedVector testVec (NUM_ELMS);
295 for_each (testVec, showInt);
298 WrappedVector
const& ref (testVec);
299 for_each (ref, showInt);
309 TestContainer
const& const_elms (elms);
312 for (TestContainer::iterator
iter = elms.begin();
317 CHECK (
iter != elms.end());
320 CHECK (**
iter == i-1);
324 for (TestContainer::const_iterator
iter = const_elms.begin();
329 CHECK (
iter != elms.end());
330 CHECK (**
iter == i-1);
339 for (TestContainer::ref_iterator
iter = elms.begin_ref();
344 CHECK ((*
iter) == i-1);
346 CHECK ((*
iter) == i);
350 for (TestContainer::const_ref_iter
iter = const_elms.begin_ref();
355 CHECK ((*
iter) == i);
363 for (
auto& elm : elms)
370 CHECK (
size_t(i) == elms.size());
373 for (
auto const& elm : elms)
379 CHECK (
size_t(i) == elms.size());
382 for (
auto const& elm : const_elms)
388 CHECK (
size_t(i) == elms.size());
398 for (uint i=0; i < NUM_ELMS; ++i)
401 typedef vector<int>::iterator RawIter;
405 AddrIter ii(Range(numbz.begin(), numbz.end()));
406 for (uint i=0; i < numbz.size(); ++i)
410 CHECK (p == & numbz[i]);
418 typedef vector<int>::const_iterator ConstRawIter;
422 ConstAddrIter iic(ConstRange(Range(numbz.begin(), numbz.end())));
423 for (uint i=0; i < numbz.size(); ++i)
427 CHECK (p == & numbz[i]);
440 TestContainer::ref_iterator rI (elms.begin_ref());
447 TestContainer
const& const_elms (elms);
448 TestContainer::const_ref_iter rI2 (const_elms.begin_ref());
451 CHECK (rI2 == elms.begin_ref());
452 CHECK (rI2 == const_elms.begin_ref());
458 CHECK (!isnil (rI2));
460 CHECK (TestContainer::iterator() == elms.end());
461 CHECK (!(TestContainer::iterator()));
462 CHECK (!(elms.end()));
463 CHECK (isnil (elms.end()));
465 CHECK (elms.begin());
466 CHECK (!isnil (elms.begin()));
wrapper for an existing Iterator type, automatically dereferencing the output of the former...
void simpleUsage(CON &elms)
Extension adapter for Lumiera Forward Iterators to dereference any pointer values automatically...
Example of a more elaborate custom container exposing an iteration API.
example of simply wrapping an STL container and exposing a range as Lumiera Forward Iterator ...
NumIter< INT > eachNum(INT start, INT end)
convenience function to iterate "each number"
Helper template(s) for creating Lumiera Forward Iterators.
void iterTypeVariations(TestContainer &elms)
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
void exposeDataAddresses()
Implementation namespace for support and library code.
wrapper for an existing Iterator type to expose the address of each value yielded.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
void for_each(CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
Accept binding for arbitrary function arguments.
A collection of frequently used helper functions to support unit testing.
Accessing a STL element range through a Lumiera forward iterator, An instance of this iterator adapte...
friend bool checkPoint(const TestContainer *src, ITER &pos)
Implementation of Iteration-logic: detect iteration end.
friend void iterNext(const TestContainer *, ITER &pos)
Implementation of Iteration-logic: pull next element.
void verifyComparisons(TestContainer &elms)
Perform operations "for each element" of a collection.
Adapter for building an implementation of the »Lumiera Forward Iterator« concept. ...