Here is the base class for my iterators:
Code:
template<typename VecT, typename VecTraits, typename Base, typename BaseIterator, typename DerefType> class CIteratorBase:
public boost::addable<CIteratorBaseTmpl, uint32_t>,
public boost::subtractable<CIteratorBaseTmpl, uint32_t>,
public boost::addable<CIteratorBaseTmpl>,
public boost::subtractable<CIteratorBaseTmpl>
//public std::iterator<std::random_access_iterator_tag, VecT>
{
public:
CIteratorBase();
CIteratorBase(DerefType* pStartPos, const VecT* pRangeStart, const VecT* pRangeEnd);
CIteratorBase(const CConstIterator<VecT, VecTraits, Base>& rSrc);
CIteratorBase(const CIterator<VecT, VecTraits, Base>& rSrc);
CIteratorBase& operator ++ ();
CIteratorBase operator ++ (int);
CIteratorBase& operator -- ();
CIteratorBase operator -- (int);
CIteratorBase& operator += (uint32_t nPos);
CIteratorBase& operator -= (uint32_t nPos);
CIteratorBase& operator += (const CIteratorBaseTmpl& vPos);
CIteratorBase& operator -= (const CIteratorBaseTmpl& vPos);
DerefType& operator * () const;
CIteratorValue<uint32_t, DerefType, VecTraits, Base, CIteratorBase, DerefType>* operator -> ();
bool valid();
friend bool operator < <> (const CIteratorBaseTmpl& rLeft, const CIteratorBaseTmpl& rRight);
friend bool operator == <> (const CIteratorBaseTmpl& rLeft, const CIteratorBaseTmpl& rRight);
friend bool operator > <> (const CIteratorBaseTmpl& rLeft, const CIteratorBaseTmpl& rRight);
friend bool operator != <> (const CIteratorBaseTmpl& rLeft, const CIteratorBaseTmpl& rRight);
CIteratorBase& operator = (const CIteratorBase& rSrc);
void SetSafe();
friend uint32_t Difference <> (const CIteratorBaseTmpl& v1, const CIteratorBaseTmpl& v2);
protected:
/*template<typename T> */void Copy(const CIteratorBaseTmpl& rObj);
DerefType* m_pCurPos;
const VecT* m_pRangeStart;
const VecT* m_pRangeEnd;
bool bUnsafe;
CIteratorValue<uint32_t, DerefType, VecTraits, Base, CIteratorBaseTmpl, DerefType> m_Value;
#ifdef _DEBUG
void DebugChecks() const;
#endif
};
The incompability is this line in STL:
Code:
_OutIt _Result = _Dest - (_Last - _First);
As I explained, using operator - on my iterator will cause it to return an object of itself, not the distance between them.
OK, so it might be fine, but again, it's mixing iterators. _Last and _First are constant. They are incompatible with _Dest which is non-constant.
STL is incredibly unsafe. It completely disregards the const and assigns anyway.
Even trying to fit an iterator into this design gives incredible amount of headaches.
I didn't even want a const_iterator at first but I had to due to const functions.
There I need to provide conversion.
STL is working in extremely unsafe ways that just won't be compatible with my implementations, I can almost guarantee that.
And since you asked... my iterator functions:
Code:
// Iterators
typedef Iterators::CIterator<T, Traits, CTmplStringBase> iterator;
typedef Iterators::CConstIterator<T, Traits, CTmplStringBase> const_iterator;
iterator begin();
iterator end();
//iterator EndOfString();
const_iterator const_begin() const;
const_iterator const_end() const;
The iterators are completely different types. They are NOT compatible.