title | description | ms.date | ms.topic | f1_keywords | helpviewer_keywords | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
queue (STL/CLR) |
Learn more about: queue (STL/CLR) |
4/20/2023 |
reference |
|
|
The template class describes an object that controls a varying length sequence of elements that has first-in first-out access. Use the container adapter queue
to manage an underlying container as a queue.
In the following description, GValue
is the same as Value
unless the latter is a ref type, in which case it's Value^
. Similarly, GContainer
is the same as Container
unless the latter is a ref type, in which case it's Container^
.
template<typename Value,
typename Container>
ref class queue
: public
System::ICloneable,
Microsoft::VisualC::StlClr::IQueue<GValue, GContainer>
{ ..... };
Value
The type of an element in the controlled sequence.
Container
The type of the underlying container.
Header: <cliext/queue>
Namespace: cliext
Important
To compile the examples in this topic, ensure that you have installed C++/CLI support as described in Install C++/CLI support in Visual Studio 2022. For the project type, create a CLR Console app (.NET Framework).
Type definition | Description |
---|---|
queue::const_reference |
The type of a constant reference to an element. |
queue::container_type |
The type of the underlying container. |
queue::difference_type |
The type of a signed distance between two elements. |
queue::generic_container |
The type of the generic interface for the container adapter. |
queue::generic_value |
The type of an element for the generic interface for the container adapter. |
queue::reference |
The type of a reference to an element. |
queue::size_type |
The type of a signed distance between two elements. |
queue::value_type |
The type of an element. |
Member function | Description |
---|---|
queue::assign |
Replaces all elements. |
queue::back |
Accesses the last element. |
queue::empty |
Tests whether no elements are present. |
queue::front |
Accesses the first element. |
queue::get_container |
Accesses the underlying container. |
queue::pop |
Removes the first element. |
queue::push |
Adds a new last element. |
queue::queue |
Constructs a container object. |
queue::size |
Counts the number of elements. |
queue::to_array |
Copies the controlled sequence to a new array. |
Property | Description |
---|---|
queue::back_item |
Accesses the last element. |
queue::front_item |
Accesses the first element. |
Operator | Description |
---|---|
queue::operator= |
Replaces the controlled sequence. |
operator!= (queue) |
Determines if a queue object isn't equal to another queue object. |
operator< (queue) |
Determines if a queue object is less than another queue object. |
operator<= (queue) |
Determines if a queue object is less than or equal to another queue object. |
operator== (queue) |
Determines if a queue object is equal to another queue object. |
operator> (queue) |
Determines if a queue object is greater than another queue object. |
operator>= (queue) |
Determines if a queue object is greater than or equal to another queue object. |
Interface | Description |
---|---|
xref:System.ICloneable | Duplicate an object. |
IQueue<Value, Container> |
Maintain generic container adapter. |
The object allocates and frees storage for the sequence it controls through an underlying container of type Container
that stores Value
elements and grows on demand. The object restricts access to just pushing the first element and popping the last element, implementing a first-in first-out queue (also known as a FIFO queue, or simply a queue).
Replaces all elements.
void assign(queue<Value, Container>% right);
right
Container adapter to insert.
The member function assigns right.get_container()
to the underlying container. You use it to change the entire contents of the queue.
// cliext_queue_assign.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// assign a repetition of values
Myqueue c2;
c2.assign(c1);
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
a b c
Accesses the last element.
reference back();
The member function returns a reference to the last element of the controlled sequence, which must be nonempty. You use it to access the last element, when you know one exists.
// cliext_queue_back.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// inspect last item
System::Console::WriteLine("back() = {0}", c1.back());
// alter last item and reinspect
c1.back() = L'x';
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
back() = c
a b x
Accesses the last element.
property value_type back_item;
The property accesses the last element of the controlled sequence, which must be nonempty. You use it to read or write the last element, when you know one exists.
// cliext_queue_back_item.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// inspect last item
System::Console::WriteLine("back_item = {0}", c1.back_item);
// alter last item and reinspect
c1.back_item = L'x';
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
back_item = c
a b x
The type of a constant reference to an element.
typedef value_type% const_reference;
The type describes a constant reference to an element.
// cliext_queue_const_reference.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents "a b c"
for (; !c1.empty(); c1.pop())
{ // get a const reference to an element
Myqueue::const_reference cref = c1.front();
System::Console::Write("{0} ", cref);
}
System::Console::WriteLine();
return (0);
}
a b c
The type of the underlying container.
typedef Container value_type;
The type is a synonym for the template parameter Container
.
// cliext_queue_container_type.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents "a b c" using container_type
Myqueue::container_type wc1 = c1.get_container();
for each (wchar_t elem in wc1)
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
The types of a signed distance between two elements.
typedef int difference_type;
The type describes a possibly negative element count.
// cliext_queue_difference_type.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// compute negative difference
Myqueue::difference_type diff = c1.size();
c1.push(L'd');
c1.push(L'e');
diff -= c1.size();
System::Console::WriteLine("pushing 2 = {0}", diff);
// compute positive difference
diff = c1.size();
c1.pop();
c1.pop();
c1.pop();
diff -= c1.size();
System::Console::WriteLine("popping 3 = {0}", diff);
return (0);
}
a b c
pushing 2 = -2
popping 3 = 3
Tests whether no elements are present.
bool empty();
The member function returns true for an empty controlled sequence. It's equivalent to size() == 0
. You use it to test whether the queue
is empty.
// cliext_queue_empty.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
System::Console::WriteLine("size() = {0}", c1.size());
System::Console::WriteLine("empty() = {0}", c1.empty());
// clear the container and reinspect
c1.pop();
c1.pop();
c1.pop();
System::Console::WriteLine("size() = {0}", c1.size());
System::Console::WriteLine("empty() = {0}", c1.empty());
return (0);
}
a b c
size() = 3
empty() = False
size() = 0
empty() = True
Accesses the first element.
reference front();
The member function returns a reference to the first element of the controlled sequence, which must be nonempty. You use it to access the first element, when you know one exists.
// cliext_queue_front.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// inspect first item
System::Console::WriteLine("front() = {0}", c1.front());
// alter first item and reinspect
c1.front() = L'x';
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
front() = a
x b c
Accesses the first element.
property value_type front_item;
The property accesses the first element of the controlled sequence, which must be nonempty. You use it to read or write the first element, when you know one exists.
// cliext_queue_front_item.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// inspect last item
System::Console::WriteLine("front_item = {0}", c1.front_item);
// alter last item and reinspect
c1.front_item = L'x';
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
front_item = a
x b c
The type of the generic interface for the container adapter.
typedef Microsoft::VisualC::StlClr::IQueue<Value>
generic_container;
The type describes the generic interface for this template container adapter class.
// cliext_queue_generic_container.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// construct a generic container
Myqueue::generic_container^ gc1 = %c1;
for each (wchar_t elem in gc1->get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// modify generic and display original
gc1->push(L'd');
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// modify original and display generic
c1.push(L'e');
for each (wchar_t elem in gc1->get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
a b c
a b c d
a b c d e
The type of an element for use with the generic interface for the container.
typedef GValue generic_value;
The type describes an object of type GValue
that describes the stored element value for use with the generic interface for this template container class. (GValue
is either value_type
or value_type^
if value_type
is a ref type.)
// cliext_queue_generic_value.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// get interface to container
Myqueue::generic_container^ gc1 = %c1;
for each (wchar_t elem in gc1->get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// display in order using generic_value
for (; !gc1->empty(); gc1->pop())
{
Myqueue::generic_value elem = gc1->front();
System::Console::Write("{0} ", elem);
}
System::Console::WriteLine();
return (0);
}
a b c
a b c
a b c
Accesses the underlying container.
container_type^ get_container();
The member function returns the underlying container. You use it to bypass the restrictions imposed by the container wrapper.
// cliext_queue_get_container.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
Replaces the controlled sequence.
queue <Value, Container>% operator=(queue <Value, Container>% right);
right
Container adapter to copy.
The member operator copies right
to the object, then returns *this
. You use it to replace the controlled sequence with a copy of the controlled sequence in right
.
// cliext_queue_operator_as.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// assign to a new container
Myqueue c2;
c2 = c1;
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
a b c
Removes the first element.
void pop();
Removes the first element of the controlled sequence, which must be nonempty.
// cliext_queue_pop.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// pop an element and redisplay
c1.pop();
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
b c
Adds a new last element.
void push(value_type val);
The member function adds an element with value val
at the end of the queue. You use it to append an element to the queue.
// cliext_queue_push.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
Constructs a container adapter object.
queue();
queue(queue<Value, Container>% right);
queue(queue<Value, Container>^ right);
explicit queue(container_type% wrapped);
right
Object to copy.
wrapped
Wrapped container to use.
The constructor:
queue();
creates an empty wrapped container. You use it to specify an empty initial controlled sequence.
The constructor:
queue(queue<Value, Container>% right);
creates a wrapped container that is a copy of right.get_container()
. You use it to specify an initial controlled sequence that is a copy of the sequence controlled by the queue
object right
.
The constructor:
queue(queue<Value, Container>^ right);
creates a wrapped container that is a copy of right->get_container()
. You use it to specify an initial controlled sequence that is a copy of the sequence controlled by the queue
object *right
.
The constructor:
explicit queue(container_type wrapped);
uses the existing container wrapped
as the wrapped container. You use it to construct a queue
from an existing container.
// cliext_queue_construct.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
#include <cliext/list>
typedef cliext::queue<wchar_t> Myqueue;
typedef cliext::list<wchar_t> Mylist;
typedef cliext::queue<wchar_t, Mylist> Myqueue_list;
int main()
{
// construct an empty container
Myqueue c1;
System::Console::WriteLine("size() = {0}", c1.size());
// construct from an underlying container
Mylist v2(5, L'x');
Myqueue_list c2(v2);
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// construct by copying another container
Myqueue_list c3(c2);
for each (wchar_t elem in c3.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// construct by copying another container through handle
Myqueue_list c4(%c2);
for each (wchar_t elem in c4.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
size() = 0
x x x x x
x x x x x
x x x x x
The type of a reference to an element.
typedef value_type% reference;
The type describes a reference to an element.
// cliext_queue_reference.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// modify back of queue and redisplay
Myqueue::reference ref = c1.back();
ref = L'x';
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c
a b x
Counts the number of elements.
size_type size();
The member function returns the length of the controlled sequence. You use it to determine the number of elements currently in the controlled sequence. If all you care about is whether the sequence has nonzero size, see empty()
.
// cliext_queue_size.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
System::Console::WriteLine("size() = {0} starting with 3", c1.size());
// pop an item and reinspect
c1.pop();
System::Console::WriteLine("size() = {0} after popping", c1.size());
// add two elements and reinspect
c1.push(L'a');
c1.push(L'b');
System::Console::WriteLine("size() = {0} after adding 2", c1.size());
return (0);
}
a b c
size() = 3 starting with 3
size() = 2 after popping
size() = 4 after adding 2
The type of a signed distance between two elements.
typedef int size_type;
The type describes a non-negative element count.
// cliext_queue_size_type.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display initial contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// compute positive difference
Myqueue::size_type diff = c1.size();
c1.pop();
c1.pop();
diff -= c1.size();
System::Console::WriteLine("size difference = {0}", diff);
return (0);
}
a b c
size difference = 2
Copies the controlled sequence to a new array.
cli::array<Value>^ to_array();
The member function returns an array containing the controlled sequence. You use it to obtain a copy of the controlled sequence in array form.
// cliext_queue_to_array.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// copy the container and modify it
cli::array<wchar_t>^ a1 = c1.to_array();
c1.push(L'd');
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// display the earlier array copy
for each (wchar_t elem in a1)
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
return (0);
}
a b c d
a b c
The type of an element.
typedef Value value_type;
The type is a synonym for the template parameter Value
.
// cliext_queue_value_type.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display reversed contents "a b c" using value_type
for (; !c1.empty(); c1.pop())
{ // store element in value_type object
Myqueue::value_type val = c1.front();
System::Console::Write("{0} ", val);
}
System::Console::WriteLine();
return (0);
}
a b c
Queue
not equal comparison.
template<typename Value,
typename Container>
bool operator!=(queue<Value, Container>% left,
queue<Value, Container>% right);
left
Left container to compare.
right
Right container to compare.
The operator function returns !(left == right)
. You use it to test whether left
isn't ordered the same as right
when the two queues are compared element by element.
// cliext_queue_operator_ne.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// assign to a new container
Myqueue c2;
c2.push(L'a');
c2.push(L'b');
c2.push(L'd');
// display contents "a b d"
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
System::Console::WriteLine("[a b c] != [a b c] is {0}",
c1 != c1);
System::Console::WriteLine("[a b c] != [a b d] is {0}",
c1 != c2);
return (0);
}
a b c
a b d
[a b c] != [a b c] is False
[a b c] != [a b d] is True
Queue
less than comparison.
template<typename Value,
typename Container>
bool operator<(queue<Value, Container>% left,
queue<Value, Container>% right);
left
Left container to compare.
right
Right container to compare.
The operator function returns true if, for the lowest position i
for which !(right[i] < left[i])
it's also true that left[i] < right[i]
. Otherwise, it returns left->size() < right->size()
. You use it to test whether left
is ordered before right
when the two queues are compared element by element.
// cliext_queue_operator_lt.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// assign to a new container
Myqueue c2;
c2.push(L'a');
c2.push(L'b');
c2.push(L'd');
// display contents "a b d"
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
System::Console::WriteLine("[a b c] < [a b c] is {0}",
c1 < c1);
System::Console::WriteLine("[a b c] < [a b d] is {0}",
c1 < c2);
return (0);
}
a b c
a b d
[a b c] < [a b c] is False
[a b c] < [a b d] is True
Queue
less than or equal comparison.
template<typename Value,
typename Container>
bool operator<=(queue<Value, Container>% left,
queue<Value, Container>% right);
left
Left container to compare.
right
Right container to compare.
The operator function returns !(right < left)
. You use it to test whether left
isn't ordered after right
when the two queues are compared element by element.
// cliext_queue_operator_le.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// assign to a new container
Myqueue c2;
c2.push(L'a');
c2.push(L'b');
c2.push(L'd');
// display contents "a b d"
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
System::Console::WriteLine("[a b c] <= [a b c] is {0}",
c1 <= c1);
System::Console::WriteLine("[a b d] <= [a b c] is {0}",
c2 <= c1);
return (0);
}
a b c
a b d
[a b c] <= [a b c] is True
[a b d] <= [a b c] is False
Queue
equal comparison.
template<typename Value,
typename Container>
bool operator==(queue<Value, Container>% left,
queue<Value, Container>% right);
left
Left container to compare.
right
Right container to compare.
The operator function returns true only if the sequences controlled by left
and right
have the same length and, for each position i
, left[i] == right[i]
. You use it to test whether left
is ordered the same as right
when the two queues are compared element by element.
// cliext_queue_operator_eq.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// assign to a new container
Myqueue c2;
c2.push(L'a');
c2.push(L'b');
c2.push(L'd');
// display contents "a b d"
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
System::Console::WriteLine("[a b c] == [a b c] is {0}",
c1 == c1);
System::Console::WriteLine("[a b c] == [a b d] is {0}",
c1 == c2);
return (0);
}
a b c
a b d
[a b c] == [a b c] is True
[a b c] == [a b d] is False
Queue
greater than comparison.
template<typename Value,
typename Container>
bool operator>(queue<Value, Container>% left,
queue<Value, Container>% right);
left
Left container to compare.
right
Right container to compare.
The operator function returns right < left
. You use it to test whether left
is ordered after right
when the two queues are compared element by element.
// cliext_queue_operator_gt.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// assign to a new container
Myqueue c2;
c2.push(L'a');
c2.push(L'b');
c2.push(L'd');
// display contents "a b d"
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
System::Console::WriteLine("[a b c] > [a b c] is {0}",
c1 > c1);
System::Console::WriteLine("[a b d] > [a b c] is {0}",
c2 > c1);
return (0);
}
a b c
a b d
[a b c] > [a b c] is False
[a b d] > [a b c] is True
Queue
greater than or equal comparison.
template<typename Value,
typename Container>
bool operator>=(queue<Value, Container>% left,
queue<Value, Container>% right);
left
Left container to compare.
right
Right container to compare.
The operator function returns !(left < right)
. You use it to test whether left
isn't ordered before right
when the two queues are compared element by element.
// cliext_queue_operator_ge.cpp
// compile with: /clr
#include "pch.h"
#include <cliext/queue>
typedef cliext::queue<wchar_t> Myqueue;
int main()
{
Myqueue c1;
c1.push(L'a');
c1.push(L'b');
c1.push(L'c');
// display contents "a b c"
for each (wchar_t elem in c1.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
// assign to a new container
Myqueue c2;
c2.push(L'a');
c2.push(L'b');
c2.push(L'd');
// display contents "a b d"
for each (wchar_t elem in c2.get_container())
System::Console::Write("{0} ", elem);
System::Console::WriteLine();
System::Console::WriteLine("[a b c] >= [a b c] is {0}",
c1 >= c1);
System::Console::WriteLine("[a b c] >= [a b d] is {0}",
c1 >= c2);
return (0);
}
a b c
a b d
[a b c] >= [a b c] is True
[a b c] >= [a b d] is False