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>usingnamespaceSystem;usingnamespaceSystem::Collections::Generic;voidPrintItems(constSmartPtr<IEnumerable<int>>&queue){for(constintitem:queue){std::cout<<item<<' ';}std::cout<<std::endl;}intmain(){// Create the Queue-class instance.
autoqueue=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);return0;}/*
This code example produces the following output:
1
1 2 3
1
2 3
*/