WIP allow some conversions, attempt to define the const_iterator properly
This commit is contained in:
parent
4f5fca6858
commit
165cfc7fcd
3 changed files with 82 additions and 13 deletions
|
|
@ -258,6 +258,16 @@ namespace lib {
|
|||
{ }
|
||||
|
||||
|
||||
/** allow copy,
|
||||
* when the underlying iterators
|
||||
* are compatible or convertible */
|
||||
template<class I2>
|
||||
RangeIter (I2 const& oIter)
|
||||
: p_(oIter.getPos())
|
||||
, e_(oIter.getEnd())
|
||||
{ }
|
||||
|
||||
|
||||
/* === lumiera forward iterator concept === */
|
||||
|
||||
reference
|
||||
|
|
@ -299,6 +309,12 @@ namespace lib {
|
|||
return !isValid();
|
||||
}
|
||||
|
||||
|
||||
/** access wrapped STL iterator */
|
||||
const IT& getPos() const { return p_; }
|
||||
const IT& getEnd() const { return e_; }
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void
|
||||
|
|
@ -308,18 +324,13 @@ namespace lib {
|
|||
throw lumiera::error::Invalid ("Can't iterate further",
|
||||
lumiera::error::LUMIERA_ERROR_ITER_EXHAUST);
|
||||
}
|
||||
|
||||
|
||||
/// comparison operator is allowed to access the underlying impl iterator
|
||||
template<class I1, class I2>
|
||||
friend bool operator== (RangeIter<I1> const&, RangeIter<I2> const&);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// Supporting equality comparisons...
|
||||
template<class I1, class I2>
|
||||
bool operator== (RangeIter<I1> const& il, RangeIter<I2> const& ir) { return (!il && !ir) || (il.p_ == ir.p_); }
|
||||
bool operator== (RangeIter<I1> const& il, RangeIter<I2> const& ir) { return (!il && !ir) || (il.getPos() == ir.getPos()); }
|
||||
|
||||
template<class I1, class I2>
|
||||
bool operator!= (RangeIter<I1> const& il, RangeIter<I2> const& ir) { return !(il == ir); }
|
||||
|
|
@ -374,6 +385,14 @@ namespace lib {
|
|||
{ }
|
||||
|
||||
|
||||
/** allow copy initialisation also
|
||||
* when the base iter types are convertible */
|
||||
template<class I2>
|
||||
PtrDerefIter (I2 const& oIter)
|
||||
: i_(reinterpret_cast<IT const&> (oIter.getBase())) /////////////////////////////TODO: properly guard this dangerous conversion by a traits template; the idea is to allow this conversion only for the initialisation of a "const iterator" from its sister type
|
||||
{ }
|
||||
|
||||
|
||||
/* === lumiera forward iterator concept === */
|
||||
|
||||
reference
|
||||
|
|
@ -414,19 +433,45 @@ namespace lib {
|
|||
}
|
||||
|
||||
|
||||
/// comparison operator is allowed to access the underlying impl iterator
|
||||
template<class I1, class I2>
|
||||
friend bool operator== (PtrDerefIter<I1> const&, PtrDerefIter<I2> const&);
|
||||
/** access the wrapped implementation iterator */
|
||||
IT const&
|
||||
getBase() const
|
||||
{
|
||||
return i_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/// Supporting equality comparisons...
|
||||
template<class I1, class I2>
|
||||
bool operator== (PtrDerefIter<I1> const& il, PtrDerefIter<I2> const& ir) { return il.i_ == ir.i_; }
|
||||
bool operator== (PtrDerefIter<I1> const& il, PtrDerefIter<I2> const& ir) { return il.getBase() == ir.getBase(); }
|
||||
|
||||
template<class I1, class I2>
|
||||
bool operator!= (PtrDerefIter<I1> const& il, PtrDerefIter<I2> const& ir) { return !(il == ir); }
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Helper for type rewritings:
|
||||
* get the element type for an iterator like entity
|
||||
*/
|
||||
template<class TY>
|
||||
struct IterType;
|
||||
|
||||
template<template<class,class> class Iter, class TY, class CON>
|
||||
struct IterType<Iter<TY,CON> >
|
||||
{
|
||||
typedef CON Container;
|
||||
typedef TY ElemType;
|
||||
|
||||
typedef typename RemovePtr<TY>::Type Type;
|
||||
|
||||
template<class T2>
|
||||
struct SimilarIter
|
||||
{
|
||||
typedef Iter<T2,CON> Type;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace lib
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -72,7 +72,8 @@ namespace lib {
|
|||
{
|
||||
typedef std::vector<T*> _Vec;
|
||||
typedef typename _Vec::iterator VIter;
|
||||
typedef typename _Vec::const_iterator VcIter;
|
||||
// typedef typename _Vec::const_iterator VcIter;
|
||||
typedef typename IterType<VIter>::template SimilarIter<const T**>::Type VcIter;
|
||||
|
||||
typedef RangeIter<VIter> RIter;
|
||||
typedef RangeIter<VcIter> RcIter;
|
||||
|
|
@ -83,6 +84,9 @@ namespace lib {
|
|||
typedef T & reference;
|
||||
typedef T const& const_reference;
|
||||
|
||||
typedef typename IterType<VIter>::Type Tupe;
|
||||
|
||||
|
||||
|
||||
ScopedPtrVect ()
|
||||
: _Vec()
|
||||
|
|
@ -155,8 +159,8 @@ namespace lib {
|
|||
|
||||
iterator begin() { return iterator (allPtrs()); }
|
||||
const_iterator begin() const { return const_iterator (allPtrs()); }
|
||||
iterator end() { return iterator (); }
|
||||
const_iterator end() const { return const_iterator (); }
|
||||
iterator end() { return iterator ( RIter() ); }
|
||||
const_iterator end() const { return const_iterator (RcIter() ); }
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,13 @@
|
|||
#include "lib/scoped-ptrvect.hpp"
|
||||
#include "testdummy.hpp"
|
||||
|
||||
//////////////////////////////////////////////TODO test code
|
||||
#include "lib/test/test-helper.hpp"
|
||||
using lib::test::showSizeof;
|
||||
#include <iostream>
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
//////////////////////////////////////////////TODO test code
|
||||
|
||||
namespace lib {
|
||||
namespace test{
|
||||
|
|
@ -111,6 +118,19 @@ namespace test{
|
|||
++check;
|
||||
++ii;
|
||||
}
|
||||
check = 0;
|
||||
|
||||
///////////////////////////////////////////////////////////////////TODO test code
|
||||
cout << showSizeof<VectD::Tupe> () << endl;
|
||||
///////////////////////////////////////////////////////////////////TODO test code
|
||||
|
||||
VectD::const_iterator cii = holder.begin();
|
||||
while (cii)
|
||||
{
|
||||
ASSERT (check == cii->getVal());
|
||||
++check;
|
||||
++cii;
|
||||
}
|
||||
}
|
||||
ASSERT (0==checksum);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue