Ich hab mal ne noch krausere Implementierung des ContainerEnumerator des vorherigen posts geschrieben.
Diesmal wird sie so benutzt:
vector<int> vInts;
vInts.push_back(1);
enumiterator<vector <int> > enumIt(&vInts);
while(enumIt++)
{
...
}
C++:
-
template <class _T, class _I = _T::iterator>
-
class enumiterator : public _I
-
{
-
public:
-
enumiterator(_T* pContainer)
-
{
-
*((_I*)this) = pContainer->begin();
-
m_pContainer = pContainer;
-
}
-
bool operator++()
-
{
-
if(*this != m_pContainer->end())
-
{
-
(*((_I*)this))++;
-
return true;
-
}
-
else
-
return false;
-
}
-
bool operator++(int)
-
{
-
if(*this != m_pContainer->end())
-
{
-
(*((_I*)this))++;
-
return true;
-
}
-
else
-
return false;
-
}
-
protected:
-
_T* m_pContainer;
-
};