stack (STL/CLR)

The template class describes an object that controls a varying-length sequence of elements that has last-in first-out access. You use the container adapter stack to manage an underlying container as a push-down stack.

In the description below, 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^.

Syntax

template<typename Value,
    typename Container>
    ref class stack
        :   public
        System::ICloneable,
        Microsoft::VisualC::StlClr::IStack<GValue, GContainer>
    { ..... };

Parameters

Value
The type of an element in the controlled sequence.

Container
The type of the underlying container.

Requirements

Header: <cliext/stack>

Namespace: cliext

Declarations

Type definition Description
stack::const_reference The type of a constant reference to an element.
stack::container_type The type of the underlying container.
stack::difference_type The type of a signed distance between two elements.
stack::generic_container The type of the generic interface for the container adapter.
stack::generic_value The type of an element for the generic interface for the container adapter.
stack::reference The type of a reference to an element.
stack::size_type The type of a signed distance between two elements.
stack::value_type The type of an element.
Member function Description
stack::assign Replaces all elements.
stack::empty Tests whether no elements are present.
stack::get_container Accesses the underlying container.
stack::pop Removes the last element.
stack::push Adds a new last element.
stack::size Counts the number of elements.
stack::stack Constructs a container object.
stack::top Accesses the last element.
stack::to_array Copies the controlled sequence to a new array.
Property Description
stack::top_item Accesses the last element.
Operator Description
stack::operator= Replaces the controlled sequence.
operator!= (stack) Determines if a stack object isn't equal to another stack object.
operator< (stack) Determines if a stack object is less than another stack object.
operator<= (stack) Determines if a stack object is less than or equal to another stack object.
operator== (stack) Determines if a stack object is equal to another stack object.
operator> (stack) Determines if a stack object is greater than another stack object.
operator>= (stack) Determines if a stack object is greater than or equal to another stack object.

Interfaces

Interface Description
ICloneable Duplicate an object.
IStack<Value, Container> Maintain generic container adapter.

Remarks

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 pushing and popping just the last element, implementing a last-in first-out queue (also known as a LIFO queue, or stack).

Members

stack::assign

Replaces all elements.

Syntax

void assign(stack<Value, Container>% right);

Parameters

right
Container adapter to insert.

Remarks

The member function assigns right.get_container() to the underlying container. You use it to change the entire contents of the stack.

Example

// cliext_stack_assign.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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
    Mystack 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

stack::const_reference

The type of a constant reference to an element.

Syntax

typedef value_type% const_reference;

Remarks

The type describes a constant reference to an element.

Example

// cliext_stack_const_reference.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack c1;
    c1.push(L'a');
    c1.push(L'b');
    c1.push(L'c');

// display reversed contents " c b a"
    for (; !c1.empty(); c1.pop())
        {   // get a const reference to an element
        Mystack::const_reference cref = c1.top();
        System::Console::Write("{0} ", cref);
        }
    System::Console::WriteLine();
    return (0);
    }
c b a

stack::container_type

The type of the underlying container.

Syntax

typedef Container value_type;

Remarks

The type is a synonym for the template parameter Container.

Example

// cliext_stack_container_type.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack c1;
    c1.push(L'a');
    c1.push(L'b');
    c1.push(L'c');

// display contents " a b c" using container_type
    Mystack::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

stack::difference_type

The types of a signed distance between two elements.

Syntax

typedef int difference_type;

Remarks

The type describes a possibly negative element count.

Example

// cliext_stack_difference_type.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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
    Mystack::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

stack::empty

Tests whether no elements are present.

Syntax

bool empty();

Remarks

The member function returns true for an empty controlled sequence. It's equivalent to size() == 0. You use it to test whether the stack is empty.

Example

// cliext_stack_empty.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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

stack::generic_container

The type of the generic interface for the container adapter.

Syntax

typedef Microsoft::VisualC::StlClr::IStack<Value>
    generic_container;

Remarks

The type describes the generic interface for this template container adapter class.

Example

// cliext_stack_generic_container.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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
    Mystack::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

stack::generic_value

The type of an element for use with the generic interface for the container.

Syntax

typedef GValue generic_value;

Remarks

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.)

Example

// cliext_stack_generic_value.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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
    Mystack::generic_container^ gc1 = %c1;
    for each (wchar_t elem in gc1->get_container())
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

// display in reverse using generic_value
    for (; !gc1->empty(); gc1->pop())
        {
        Mystack::generic_value elem = gc1->top();

        System::Console::Write("{0} ", elem);
        }
    System::Console::WriteLine();
    return (0);
    }
a b c
a b c
c b a

stack::get_container

Accesses the underlying container.

Syntax

container_type^ get_container();

Remarks

The member function returns a handle for underlying container. You use it to bypass the restrictions imposed by the container wrapper.

Example

// cliext_stack_get_container.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack c1;
    c1.push(L'a');
    c1.push(L'b');
    c1.push(L'c');

// display contents " a b c" using container_type
    Mystack::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

stack::operator=

Replaces the controlled sequence.

Syntax

stack<Value, Container>% operator=(stack<Value, Container>% right);

Parameters

right
Container adapter to copy.

Remarks

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.

Example

// cliext_stack_operator_as.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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
    Mystack 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

stack::pop

Removes the last element.

Syntax

void pop();

Remarks

The member function removes the last element of the controlled sequence, which must be non-empty. You use it to shorten the stack by one element at the back.

Example

// cliext_stack_pop.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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
a b

stack::push

Adds a new last element.

Syntax

void push(value_type val);

Remarks

The member function inserts an element with value val at the end of the controlled sequence. You use it to append another element to the stack.

Example

// cliext_stack_push.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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

stack::reference

The type of a reference to an element.

Syntax

typedef value_type% reference;

Remarks

The type describes a reference to an element.

Example

// cliext_stack_reference.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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 top of stack and redisplay
    Mystack::reference ref = c1.top();
    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

stack::size

Counts the number of elements.

Syntax

size_type size();

Remarks

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 stack::empty.

Example

// cliext_stack_size.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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

stack::size_type

The type of a signed distance between two elements.

Syntax

typedef int size_type;

Remarks

The type describes a non-negative element count.

Example

// cliext_stack_size_type.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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
    Mystack::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

stack::stack

Constructs a container adapter object.

Syntax

stack();
stack(stack<Value, Container>% right);
stack(stack<Value, Container>^ right);
explicit stack(container_type% wrapped);

Parameters

right
Object to copy.

wrapped
Wrapped container to use.

Remarks

The constructor:

stack();

creates an empty wrapped container. You use it to specify an empty initial controlled sequence.

The constructor:

stack(stack<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 stack object right.

The constructor:

stack(stack<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 stack object *right.

The constructor:

explicit stack(container_type% wrapped);

uses the existing container wrapped as the wrapped container. You use it to construct a stack from an existing container.

Example

// cliext_stack_construct.cpp
// compile with: /clr
#include <cliext/stack>
#include <cliext/vector>

typedef cliext::stack<wchar_t> Mystack;
typedef cliext::vector<wchar_t> Myvector;
typedef cliext::stack<wchar_t, Myvector> Mystack_vec;
int main()
    {
// construct an empty container
    Mystack c1;
    System::Console::WriteLine("size() = {0}", c1.size());

// construct from an underlying container
    Myvector v2(5, L'x');
    Mystack_vec c2(v2);
    for each (wchar_t elem in c2.get_container())
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

// construct by copying another container
    Mystack_vec 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
    Mystack_vec 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

stack::to_array

Copies the controlled sequence to a new array.

Syntax

cli::array<Value>^ to_array();

Remarks

The member function returns an array containing the controlled sequence. You use it to obtain a copy of the controlled sequence in array form.

Example

// cliext_stack_to_array.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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

stack::top

Accesses the last element.

Syntax

reference top();

Remarks

The member function returns a reference to the last element of the controlled sequence, which must be non-empty. You use it to access the last element, when you know one exists.

Example

// cliext_stack_top.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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("top() = {0}", c1.top());

// alter last item and reinspect
    c1.top() = L'x';
    for each (wchar_t elem in c1.get_container())
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
top() = c
a b x

stack::top_item

Accesses the last element.

Syntax

property value_type top_item;

Remarks

The property accesses the last element of the controlled sequence, which must be non-empty. You use it to read or write the last element, when you know one exists.

Example

// cliext_stack_top_item.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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("top_item = {0}", c1.top_item);

// alter last item and reinspect
    c1.top_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
top_item = c
a b x

stack::value_type

The type of an element.

Syntax

typedef Value value_type;

Remarks

The type is a synonym for the template parameter Value.

Example

// cliext_stack_value_type.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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
        Mystack::value_type val = c1.top();

        System::Console::Write("{0} ", val);
        }
    System::Console::WriteLine();
    return (0);
    }
c b a

operator!= (stack)

Stack not equal comparison.

Syntax

template<typename Value,
    typename Container>
    bool operator!=(stack<Value, Container>% left,
        stack<Value, Container>% right);

Parameters

left
Left container to compare.

right
Right container to compare.

Remarks

The operator function returns !(left == right). You use it to test whether left isn't ordered the same as right when the two stacks are compared element by element.

Example

// cliext_stack_operator_ne.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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
    Mystack 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

operator< (stack)

Stack less than comparison.

Syntax

template<typename Value,
    typename Container>
    bool operator<(stack<Value, Container>% left,
        stack<Value, Container>% right);

Parameters

left
Left container to compare.

right
Right container to compare.

Remarks

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 stacks are compared element by element.

Example

// cliext_stack_operator_lt.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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
    Mystack 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

operator<= (stack)

Stack less than or equal comparison.

Syntax

template<typename Value,
    typename Container>
    bool operator<=(stack<Value, Container>% left,
        stack<Value, Container>% right);

Parameters

left
Left container to compare.

right
Right container to compare.

Remarks

The operator function returns !(right < left). You use it to test whether left isn't ordered after right when the two stacks are compared element by element.

Example

// cliext_stack_operator_le.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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
    Mystack 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

operator== (stack)

Stack equal comparison.

Syntax

template<typename Value,
    typename Container>
    bool operator==(stack<Value, Container>% left,
        stack<Value, Container>% right);

Parameters

left
Left container to compare.

right
Right container to compare.

Remarks

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 stacks are compared element by element.

Example

// cliext_stack_operator_eq.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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
    Mystack 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

operator> (stack)

Stack greater than comparison.

Syntax

template<typename Value,
    typename Container>
    bool operator>(stack<Value, Container>% left,
        stack<Value, Container>% right);

Parameters

left
Left container to compare.

right
Right container to compare.

Remarks

The operator function returns right < left. You use it to test whether left is ordered after right when the two stacks are compared element by element.

Example

// cliext_stack_operator_gt.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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
    Mystack 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

operator>= (stack)

Stack greater than or equal comparison.

Syntax

template<typename Value,
    typename Container>
    bool operator>=(stack<Value, Container>% left,
        stack<Value, Container>% right);

Parameters

left
Left container to compare.

right
Right container to compare.

Remarks

The operator function returns !(left < right). You use it to test whether left isn't ordered before right when the two stacks are compared element by element.

Example

// cliext_stack_operator_ge.cpp
// compile with: /clr
#include <cliext/stack>

typedef cliext::stack<wchar_t> Mystack;
int main()
    {
    Mystack 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
    Mystack 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