System::Collections::Generic::IEnumerator class

IEnumerator class

Interface of enumerator which can be used to iterate through some elements. Objects of this class should only be allocated using System::MakeObject() function. Never create instance of this type on stack or using operator new, as it will result in runtime errors and/or assertion faults. Always wrap this class into System::SmartPtr pointer and use this pointer to pass it to functions as argument.

template<typename T>class IEnumerator : public virtual System::IDisposable,
                                        public System::Details::EnumeratorBasedIterator<T>,
                                        protected System::Details::IteratorPointerUpdater<T, false>
ParameterDescription
TElement type.

Methods

MethodDescription
AsVirtualizedIterator()Prepares the iterator to be used by the VirtualizedIterator class.
CloneIterator() const overrideClones current iterator.
virtual Current() constGets current element.
virtual get_Current() constGets current element.
IEnumerator()
IncrementIterator() overrideMoves the iterator step forward.
InitializeIterator() overrideDoes the first MoveNext() call and prepares the enumerator object to be used by VirtualizedIterator.
MarkOwnedByVirtualizedIterator()Marks the enumerator owned by virtualized iterator.
virtual MoveNext()Moves enumerator to the next element. If no element was referenced before, sets reference to the first element available. If container end was hit, does nothing.
virtual Reset()Resets enumerator to position before first element.
virtual ~IEnumerator()

Typedefs

TypedefDescription
ValueTypeValue type.

Remarks

#include <system/collections/list.h>
#include <system/smart_ptr.h>

using namespace System;
using namespace System::Collections::Generic;

int main()
{
  // Create the List-class instance.
  auto collection = MakeObject<List<int>>();

  // Fill the list.
  collection->Add(1);
  collection->Add(2);
  collection->Add(3);

  // Get the enumerator of the list.
  auto enumerator = collection->GetEnumerator();

  while (enumerator->MoveNext())
  {
    // Get the current element and print it.
    std::cout << enumerator->get_Current() << ' ';
  }

  // Reset the enumerator.
  enumerator->Reset();

  return 0;
}
/*
This code example produces the following output:
1 2 3
*/

See Also