System::Collections::Generic::Queue class

Queue class

Queue class forward declaration.

template<typename T>class Queue : public System::Collections::Generic::IEnumerable<T>
ParameterDescription
TElement type.

Nested classes

Methods

MethodDescription
virtual Clear()Deletes all elements in queue.
virtual Contains(const T&) constChecks if queue contains specific element using operator == to compare elements.
data()Underlying data structure accessor.
data() constUnderlying data structure accessor.
Dequeue()Gets item from the beginning of the queue.
Enqueue(const T&)Puts item to the end of the queue.
virtual get_Count() constGets number of elements in queue.
GetEnumerator() overrideGets enumerator to iterate through the queue.
Peek()Gets item from the beginning of the queue, but does not remove it from queue.
Queue()Constructs empty queue.
Queue(int)Constructs empty queue.
Queue(const SharedPtr<IEnumerable<T>>&)Copy constructor.
virtualizeBeginConstIterator() const overrideGets the implementation of begin const iterator for the current container.
virtualizeBeginIterator() overrideGets the implementation of begin iterator for the current container.
virtualizeEndConstIterator() const overrideGets the implementation of end const iterator for the current container.
virtualizeEndIterator() overrideGets the implementation of end iterator for the current container.

Typedefs

TypedefDescription
ValueTypeThis type.
queue_tRTTI information.
IEnumerablePtrContainer of same type elements.
IEnumeratorPtrEnumerator type.

Remarks

Queue container wrapping STL list. 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.

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

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

void PrintItems(const SmartPtr<IEnumerable<int>> &queue)
{
  for (const int item: queue)
  {
    std::cout << item << ' ';
  }
  std::cout << std::endl;
}

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

  // Fill the queue.
  queue->Enqueue(1);
  queue->Enqueue(2);
  queue->Enqueue(3);

  // Print the first queue item. The Peek method doesn't remove an item from the queue.
  std::cout << queue->Peek() << std::endl;
  // Print the queue items.
  PrintItems(queue);

  // Print the first queue item. The Dequeue method removes an item from the queue.
  std::cout << queue->Dequeue() << std::endl;
  // Print the queue items.
  PrintItems(queue);

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

See Also