29 #include <boost/lexical_cast.hpp> 38 using LERR_(ITER_EXHAUST);
39 using boost::lexical_cast;
57 data_.push_back(num--);
60 typedef vector<int>::iterator sourceIter;
63 typedef vector<int>::const_iterator const_sourceIter;
66 iterator begin() {
return iterator(data_.begin(),data_.end()); }
67 iterator end() {
return iterator(); }
68 const_iterator begin()
const {
return const_iterator(data_.begin(),data_.end()); }
69 const_iterator end()
const {
return const_iterator(); }
83 typedef vector<int *> _Vec;
87 static void killIt (
int *it) {
delete it; }
94 for (uint i=0; i<count; ++i)
95 numberz_[i] =
new int(i);
100 for_each (numberz_, killIt);
113 iterator begin () {
return iterator (
this, numberz_.begin()); }
114 const_iterator begin ()
const {
return const_iterator (
this, numberz_.begin()); }
115 ref_iterator begin_ref () {
return ref_iterator (begin()); }
116 const_ref_iter begin_ref ()
const {
return const_ref_iter (begin()); }
118 iterator end () {
return iterator(); }
119 const_iterator end ()
const {
return const_iterator(); }
121 size_t size()
const {
return numberz_.size(); }
155 if ((pos != ITER()) && (pos != src->numberz_.end()))
189 NUM_ELMS = firstVal (arg, 10);
191 useSimpleWrappedContainer ();
195 TestContainer testElms (NUM_ELMS);
196 simpleUsage (testElms);
198 iterTypeVariations (testElms);
199 verifyComparisons (testElms);
200 exposeDataAddresses();
209 const int N = NUM_ELMS;
217 CHECK (sum == (N-1)*N / 2);
243 vector<int> iVec (NUM_ELMS);
244 for (uint i=0; i < NUM_ELMS; ++i)
247 typedef vector<int>::iterator I;
250 Range range (iVec.begin(), iVec.end());
251 CHECK (!isnil (range) || !NUM_ELMS);
256 cout <<
"::" << *range;
261 CHECK (isnil (range));
262 CHECK (range == Range());
272 for_each (elms, showIntP);
276 static void showIntP (
int* elm) { cout <<
"::" << *elm; }
277 static void showInt (
int elm) { cout <<
"::" << elm; }
282 useSimpleWrappedContainer ()
284 WrappedVector testVec (NUM_ELMS);
285 for_each (testVec, showInt);
288 WrappedVector
const& ref (testVec);
289 for_each (ref, showInt);
299 TestContainer
const& const_elms (elms);
302 for (TestContainer::iterator
iter = elms.begin();
307 CHECK (
iter != elms.end());
310 CHECK (**
iter == i-1);
314 for (TestContainer::const_iterator
iter = const_elms.begin();
319 CHECK (
iter != elms.end());
320 CHECK (**
iter == i-1);
329 for (TestContainer::ref_iterator
iter = elms.begin_ref();
334 CHECK ((*
iter) == i-1);
336 CHECK ((*
iter) == i);
340 for (TestContainer::const_ref_iter
iter = const_elms.begin_ref();
345 CHECK ((*
iter) == i);
353 for (
auto& elm : elms)
360 CHECK (
size_t(i) == elms.size());
363 for (
auto const& elm : elms)
369 CHECK (
size_t(i) == elms.size());
372 for (
auto const& elm : const_elms)
378 CHECK (
size_t(i) == elms.size());
388 for (uint i=0; i < NUM_ELMS; ++i)
391 typedef vector<int>::iterator RawIter;
395 AddrIter ii(Range(numbz.begin(), numbz.end()));
396 for (uint i=0; i < numbz.size(); ++i)
400 CHECK (p == & numbz[i]);
408 typedef vector<int>::const_iterator ConstRawIter;
412 ConstAddrIter iic(ConstRange(Range(numbz.begin(), numbz.end())));
413 for (uint i=0; i < numbz.size(); ++i)
417 CHECK (p == & numbz[i]);
430 TestContainer::ref_iterator rI (elms.begin_ref());
437 TestContainer
const& const_elms (elms);
438 TestContainer::const_ref_iter rI2 (const_elms.begin_ref());
441 CHECK (rI2 == elms.begin_ref());
442 CHECK (rI2 == const_elms.begin_ref());
448 CHECK (!isnil (rI2));
450 CHECK (TestContainer::iterator() == elms.end());
451 CHECK (!(TestContainer::iterator()));
452 CHECK (!(elms.end()));
453 CHECK (isnil (elms.end()));
455 CHECK (elms.begin());
456 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 ...
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.
Simplistic 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. ...
NumIter< INT > eachNum(INT start=std::numeric_limits< INT >::min(), INT end=std::numeric_limits< INT >::max())
convenience function to iterate "each number"