deque (STL/CLR)

此模板类描述了一个对象,该对象控制一个具有随机访问权限的可变长度元素序列。 可以使用容器 deque 来管理一系列元素,这些元素看起来像连续的存储块,但可以在任一端增加或减少,而无需复制任何其余元素。 因此,它可以有效地实现 double-ended queue。 (由此而得名。)

在下面的描述中,GValueValue 相同,除非后者是 ref 类型,在这种情况下它是 Value^

语法

template<typename Value>
    ref class deque
        :   public
        System::ICloneable,
        System::Collections::IEnumerable,
        System::Collections::ICollection,
        System::Collections::Generic::IEnumerable<GValue>,
        System::Collections::Generic::ICollection<GValue>,
        System::Collections::Generic::IList<GValue>,
        Microsoft::VisualC::StlClr::IDeque<GValue>
    { ..... };

参数

GValue
受控序列中的元素的泛型类型。


受控序列中的元素的类型。

要求

标头:<cliext/deque>

命名空间:cliext

声明

类型定义 说明
deque::const_iterator (STL/CLR) 受控序列的常量迭代器的类型。
deque::const_reference (STL/CLR) 元素的常量引用的类型。
deque::const_reverse_iterator (STL/CLR) 受控序列的常量反向迭代器的类型。
deque::difference_type (STL/CLR) 两个元素间的带符号距离的类型。
deque::generic_container (STL/CLR) 容器的泛型接口的类型。
deque::generic_iterator (STL/CLR) 容器的泛型接口的迭代器的类型。
deque::generic_reverse_iterator (STL/CLR) 容器的泛型接口的反向迭代器的类型。
deque::generic_value (STL/CLR) 容器的泛型接口的元素类型。
deque::iterator (STL/CLR) 受控序列的迭代器的类型。
deque::reference (STL/CLR) 元素的引用的类型。
deque::reverse_iterator (STL/CLR) 受控序列的反向迭代器的类型。
deque::size_type (STL/CLR) 两个元素间的带符号距离的类型。
deque::value_type (STL/CLR) 元素的类型。
成员函数 说明
deque::assign (STL/CLR) 替换所有元素。
deque::at (STL/CLR) 访问指定位置处的元素。
deque::back (STL/CLR) 访问最后一个元素。
deque::begin (STL/CLR) 指定受控序列的开头。
deque::clear (STL/CLR) 删除所有元素。
deque::deque (STL/CLR) 构造容器对象。
deque::empty (STL/CLR) 测试元素是否存在。
deque::end (STL/CLR) 指定受控序列的末尾。
deque::erase (STL/CLR) 移除指定位置处的元素。
deque::front (STL/CLR) 访问第一个元素。
deque::insert (STL/CLR) 在指定的位置添加元素。
deque::pop_back (STL/CLR) 删除最后一个元素。
deque::pop_front (STL/CLR) 删除第一个元素。
deque::push_back (STL/CLR) 添加新的最后一个元素。
deque::push_front (STL/CLR) 添加新的第一个元素。
deque::rbegin (STL/CLR) 指定反向受控序列的开头。
deque::rend (STL/CLR) 指定反向受控序列的末尾。
deque::resize (STL/CLR) 更改元素数目。
deque::size (STL/CLR) 对元素数进行计数。
deque::swap (STL/CLR) 交换两个容器的内容。
deque::to_array (STL/CLR) 将受控序列复制到新数组。
properties 说明
deque::back_item (STL/CLR) 访问最后一个元素。
deque::front_item (STL/CLR) 访问第一个元素。
运算符 说明
deque::operator!= (STL/CLR) 确定两个 deque 对象是否不相等。
deque::operator(STL/CLR) 访问指定位置处的元素。
operator< (deque) (STL/CLR) 确定 deque 对象是否小于另一个 deque 对象。
operator<= (deque) (STL/CLR) 确定 deque 对象是否小于或等于另一个 deque 对象。
operator= (deque) (STL/CLR) 替换受控序列。
operator== (deque) (STL/CLR) 确定 deque 对象是否等于另一个 deque 对象。
operator> (deque) (STL/CLR) 确定 deque 对象是否大于另一个 deque 对象。
operator>= (deque) (STL/CLR) 确定 deque 对象是否大于或等于另一个 deque 对象。

接口

接口 说明
ICloneable 复制对象。
IEnumerable 对元素进行排序。
ICollection 维护元素组。
IEnumerable<T> 对类型化元素进行排序。
ICollection<T> 维护类型化元素组。
IList<T> 维护有序的类型化元素组。
IDeque<Value> 维护泛型容器。

注解

该对象通过指定 Value 元素块的存储句柄数组为其控制的序列分配和释放存储。 数组按需增长。 增长以这样一种方式发生,即在前面预置或追加新元素的成本是恒定的时间,并且不会干扰其余元素。 还可以在恒定时间内删除任一端的元素,而不会干扰其余元素。 因此,双端队列非常适合模板类 queue (STL/CLR) 或模板类 stack (STL/CLR) 的基础容器。

deque 对象支持随机访问迭代器,这意味着在给定了数字位置的情况下,可以直接引用一个元素,从第一个(前面)元素的零开始计数,到最后一个(后面)元素的 deque::size (STL/CLR)() - 1。 这也意味着,双端队列非常适合模板类 priority_queue (STL/CLR) 的基础容器。

deque 迭代器存储与其关联的 deque 对象的句柄,以及它指定的元素的偏差。 只能将迭代器与其关联的容器对象一起使用。 deque 元素的偏差不一定与其位置相同。 插入的第一个元素的偏差为零,下一个追加元素的偏差为 1,但下一个在前面预置的元素的偏差为 -1。

在任一端插入或擦除元素不会更改以任何有效偏差存储的元素的值。 但是,插入或擦除内部元素可能更改以给定偏差存储的元素值,因此迭代器指定的值也可能更改。 (容器可能必须向上或向下复制元素以在插入之前创建一个洞或在擦除之后填充一个洞。)不过,只要 deque 迭代器的偏差指定有效元素,该迭代器就仍然有效。 此外,只要有效迭代器的偏差不等于 end() 返回的迭代器的偏差,该迭代器就仍可取消引用 - 可使用该迭代器访问或更改它所指定的元素值。

擦除或移除元素会为其存储的值调用析构函数。 销毁容器会擦除所有元素。 因此,元素类型为 ref 类的容器可确保没有元素的生存期长于容器。 但是,请注意,句柄的容器不会销毁其元素

成员

deque::assign (STL/CLR)

替换所有元素。

语法

void assign(size_type count, value_type val);
template<typename InIt>
    void assign(InIt first, InIt last);
void assign(System::Collections::Generic::IEnumerable<Value>^ right);

参数

count
要插入的元素数。

first
要插入的范围的开头。

last
要插入的范围的末尾。

right
要插入的枚举。

val
要插入的元素的值。

备注

第一个成员函数将受控序列替换为值 val 的 count 个重复元素。 使用它来填充具有相同值的元素的容器。

如果 InIt 是整数类型,则第二个成员函数的行为与 assign((size_type)first, (value_type)last) 相同。 否则,它将受控序列替换为序列 [first, last)。 使用它将受控序列设为另一个序列的副本。

第三个成员函数将受控序列替换为枚举器 right 指定的序列。 使用它将受控序列设为枚举器描述的序列的副本。

示例

// cliext_deque_assign.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // assign a repetition of values
    cliext::deque<wchar_t> c2;
    c2.assign(6, L'x');
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign an iterator range
    c2.assign(c1.begin(), c1.end() - 1);
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign an enumeration
    c2.assign(   // NOTE: cast is not needed
        (System::Collections::Generic::IEnumerable<wchar_t>^)%c1);
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
x x x x x x
a b
a b c

deque::at (STL/CLR)

访问指定位置处的元素。

语法

reference at(size_type pos);

参数

pos
要访问的元素的位置。

注解

成员函数返回对位置 pos 处的受控序列元素的引用。使用它来读取或写入位置已知的元素

示例

// cliext_deque_at.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c" using at
    for (int i = 0; i < c1.size(); ++i)
        System::Console::Write("{0} ", c1.at(i));
    System::Console::WriteLine();

    // change an entry and redisplay
    c1.at(1) = L'x';
    for (int i = 0; i < c1.size(); ++i)
        System::Console::Write("{0} ", c1[i]);
    System::Console::WriteLine();
    return (0);
    }
a b c
a x c

deque::back (STL/CLR)

访问最后一个元素。

语法

reference back();

备注

成员函数返回对受控序列的最后一个元素的引用,该元素必须为非空元素。 当知道它存在时,可以使用它访问最后一个元素。

示例

// cliext_deque_back.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        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)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
back() = c
a b x

deque::back_item (STL/CLR)

访问最后一个元素。

语法

property value_type back_item;

备注

该属性访问受控序列的最后一个元素,该元素必须为非空元素。 当知道它存在时,可以使用它读取或写入最后一个元素。

示例

// cliext_deque_back_item.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        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)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
back_item = c
a b x

deque::begin (STL/CLR)

指定受控序列的开头。

语法

iterator begin();

备注

该成员函数返回一个随机访问迭代器,指定受控序列的第一个元素,或刚超出空序列末尾的位置。 用于获取一个迭代器,该迭代器指定受控序列的 current 开头,但如果受控序列的长度发生更改,则该迭代器的状态也会发生更改。

示例

// cliext_deque_begin.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect first two items
    cliext::deque<wchar_t>::iterator it = c1.begin();
    System::Console::WriteLine("*begin() = {0}", *it);
    System::Console::WriteLine("*++begin() = {0}", *++it);

    // alter first two items and reinspect
    *--it = L'x';
    *++it = L'y';
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
*begin() = a
*++begin() = b
x y c

deque::clear (STL/CLR)

删除所有元素。

语法

void clear();

备注

成员函数有效调用 deque::erase (STL/CLR)(deque::begin (STL/CLR)(),deque::end (STL/CLR)())。 用于确保受控序列为空。

示例

// cliext_deque_clear.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // clear the container and reinspect
    c1.clear();
    System::Console::WriteLine("size() = {0}", c1.size());

    // add elements and clear again
    c1.push_back(L'a');
    c1.push_back(L'b');

    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    c1.clear();
    System::Console::WriteLine("size() = {0}", c1.size());
    return (0);
    }
a b c
size() = 0
a b
size() = 0

deque::const_iterator (STL/CLR)

受控序列的常量迭代器的类型。

语法

typedef T2 const_iterator;

备注

该类型描述了可充当受控序列的常量随机访问迭代器的未指定类型 T2 的对象。

示例

// cliext_deque_const_iterator.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    cliext::deque<wchar_t>::const_iterator cit = c1.begin();
    for (; cit != c1.end(); ++cit)
        System::Console::Write("{0} ", *cit);
    System::Console::WriteLine();
    return (0);
    }
a b c

deque::const_reference (STL/CLR)

元素的常量引用的类型。

语法

typedef value_type% const_reference;

备注

该类型描述了对元素的常量引用。

示例

// cliext_deque_const_reference.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    cliext::deque<wchar_t>::const_iterator cit = c1.begin();
    for (; cit != c1.end(); ++cit)
        {   // get a const reference to an element
        cliext::deque<wchar_t>::const_reference cref = *cit;
        System::Console::Write("{0} ", cref);
        }
    System::Console::WriteLine();
    return (0);
    }
a b c

deque::const_reverse_iterator (STL/CLR)

受控序列的常量反向迭代器的类型。

语法

typedef T4 const_reverse_iterator;

备注

该类型描述了可充当受控序列的常量反向迭代器的未指定类型 T4 的对象。

示例

// cliext_deque_const_reverse_iterator.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c" reversed
    cliext::deque<wchar_t>::const_reverse_iterator crit = c1.rbegin();
    cliext::deque<wchar_t>::const_reverse_iterator crend = c1.rend();
    for (; crit != crend; ++crit)
        System::Console::Write("{0} ", *crit);
    System::Console::WriteLine();
    return (0);
    }
c b a

deque::deque (STL/CLR)

构造容器对象。

语法

deque();
deque(deque<Value>% right);
deque(deque<Value>^ right);
explicit deque(size_type count);
deque(size_type count, value_type val);
template<typename InIt>
    deque(InIt first, InIt last);
deque(System::Collections::Generic::IEnumerable<Value>^ right);

参数

count
要插入的元素数。

first
要插入的范围的开头。

last
要插入的范围的末尾。

right
要插入的对象或范围。

val
要插入的元素的值。

备注

构造函数:

deque();

初始化没有元素的受控序列。 用于指定空的初始受控序列。

构造函数:

deque(deque<Value>% right);

使用序列 [right.begin(), right.end()) 初始化受控序列。 使用它来指定初始受控序列,该序列是由 deque 对象 right 控制的序列副本。 有关迭代器的详细信息,请参阅 deque::begin (STL/CLR)deque::end (STL/CLR)

构造函数:

deque(deque<Value>^ right);

使用序列 [right->begin(), right->end()) 初始化受控序列。 使用它来指定初始受控序列,该序列是由句柄为 right 的 deque 对象控制的序列副本

构造函数:

explicit deque(size_type count);

使用 count 个元素初始化受控序列,每个元素的值为 value_type()。 使用它来填充具有默认值的元素的容器。

构造函数:

deque(size_type count, value_type val);

使用 count 个元素初始化受控序列,每个元素的值为 val。 使用它来填充具有相同值的元素的容器。

构造函数:

template<typename InIt>

deque(InIt first, InIt last);

使用序列 [first, last) 初始化受控序列。 使用它将受控序列设为另一个序列的副本。

构造函数:

deque(System::Collections::Generic::IEnumerable<Value>^ right);

使用枚举器 right 指定的序列初始化受控序列。 使用它将受控序列设为枚举器描述的另一个序列的副本。

示例

// cliext_deque_construct.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
// construct an empty container
    cliext::deque<wchar_t> c1;
    System::Console::WriteLine("size() = {0}", c1.size());

    // construct with a repetition of default values
    cliext::deque<wchar_t> c2(3);
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", (int)elem);
    System::Console::WriteLine();

    // construct with a repetition of values
    cliext::deque<wchar_t> c3(6, L'x');
    for each (wchar_t elem in c3)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct with an iterator range
    cliext::deque<wchar_t>::iterator it = c3.end();
    cliext::deque<wchar_t> c4(c3.begin(), --it);
    for each (wchar_t elem in c4)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct with an enumeration
    cliext::deque<wchar_t> c5(   // NOTE: cast is not needed
        (System::Collections::Generic::IEnumerable<wchar_t>^)%c3);
    for each (wchar_t elem in c5)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct by copying another container
    cliext::deque<wchar_t> c7(c3);
    for each (wchar_t elem in c7)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct by copying a container handle
    cliext::deque<wchar_t> c8(%c3);
    for each (wchar_t elem in c8)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    return (0);
    }
size() = 0
0 0 0
x x x x x x
x x x x x
x x x x x x
x x x x x x
x x x x x x

deque::difference_type (STL/CLR)

两个元素间的带符号距离的类型。

语法

typedef int difference_type;

备注

该类型描述有符号元素计数。

示例

// cliext_deque_difference_type.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // compute positive difference
    cliext::deque<wchar_t>::difference_type diff = 0;
    for (cliext::deque<wchar_t>::iterator it = c1.begin();
        it != c1.end(); ++it) ++diff;
    System::Console::WriteLine("end()-begin() = {0}", diff);

    // compute negative difference
    diff = 0;
    for (cliext::deque<wchar_t>::iterator it = c1.end();
        it != c1.begin(); --it) --diff;
    System::Console::WriteLine("begin()-end() = {0}", diff);
    return (0);
    }
a b c
end()-begin() = 3
begin()-end() = -3

deque::empty (STL/CLR)

测试元素是否存在。

语法

bool empty();

备注

对于空受控序列,该成员函数返回 true。 它等效于 deque::size (STL/CLR)() == 0。 用于测试 deque 是否为空。

示例

// cliext_deque_empty.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        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.clear();
    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

deque::end (STL/CLR)

指定受控序列的末尾。

语法

iterator end();

备注

成员函数返回一个随机访问迭代器,它指向刚超出受控序列末尾的位置。 用于获取一个迭代器,该迭代器指定受控序列的 current 末尾,但如果受控序列的长度发生更改,则该迭代器的状态也会发生更改。

示例

// cliext_deque_end.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect last two items
    cliext::deque<wchar_t>::iterator it = c1.end();
    --it;
    System::Console::WriteLine("*-- --end() = {0}", *--it);
    System::Console::WriteLine("*--end() = {0}", *++it);

    // alter first two items and reinspect
    *--it = L'x';
    *++it = L'y';
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
*-- --end() = b
*--end() = c
a x y

deque::erase (STL/CLR)

移除指定位置处的元素。

语法

iterator erase(iterator where);
iterator erase(iterator first, iterator last);

参数

first
要擦除的范围的开头。

last
要擦除的范围的末尾。

where
要擦除的元素。

注解

第一个成员函数将删除 where 所指向的受控序列的元素。 用于删除单个元素。

第二个成员函数将移除范围 [firstlast) 中的受控序列的元素。 用于移除零个或多个连续元素。

这两个成员函数返回一个迭代器,该迭代器指定除任何已删除元素之外剩余的第一个元素,如果不存在这样的元素,则返回 deque::end (STL/CLR)()

擦除元素时,元素副本的数量与擦除末尾和序列近端之间的元素数量成线性关系。 (当擦除序列任一端的一个或多个元素时,不会出现元素副本。)

示例

// cliext_deque_erase.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // erase an element and reinspect
    System::Console::WriteLine("erase(begin()) = {0}",
        *c1.erase(c1.begin()));

    // add elements and display " b c d e"
    c1.push_back(L'd');
    c1.push_back(L'e');
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // erase all but end
    cliext::deque<wchar_t>::iterator it = c1.end();
    System::Console::WriteLine("erase(begin(), end()-1) = {0}",
        *c1.erase(c1.begin(), --it));
    System::Console::WriteLine("size() = {0}", c1.size());
    return (0);
    }
a b c
erase(begin()) = b
b c d e
erase(begin(), end()-1) = e
size() = 1

deque::front (STL/CLR)

访问第一个元素。

语法

reference front();

备注

成员函数返回对受控序列的第一个元素的引用,该元素必须为非空元素。 当知道它存在时,可以使用它读取或写入第一个元素。

示例

// cliext_deque_front.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        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)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
front() = a
x b c

deque::front_item (STL/CLR)

访问第一个元素。

语法

property value_type front_item;

备注

该属性访问受控序列的第一个元素,该元素必须为非空元素。 当知道它存在时,可以使用它读取或写入第一个元素。

示例

// cliext_deque_front_item.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect first item
    System::Console::WriteLine("front_item = {0}", c1.front_item);

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

deque::generic_container (STL/CLR)

容器的泛型接口的类型。

语法

typedef Microsoft::VisualC::StlClr::
    IDeque<generic_value>
    generic_container;

备注

该类型描述此模板容器类的泛型接口。

示例

// cliext_deque_generic_container.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct a generic container
    cliext::deque<wchar_t>::generic_container^ gc1 = %c1;
    for each (wchar_t elem in gc1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // modify generic and display original
    gc1->insert(gc1->end(), L'd');
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // modify original and display generic
    c1.push_back(L'e');

    System::Collections::IEnumerator^ enum1 =
        gc1->GetEnumerator();
    while (enum1->MoveNext())
        System::Console::Write("{0} ", enum1->Current);
    System::Console::WriteLine();
    return (0);
    }
a b c
a b c
a b c d
a b c d e

deque::generic_iterator (STL/CLR)

要与容器的泛型接口一起使用的迭代器的类型。

语法

typedef Microsoft::VisualC::StlClr::Generic::
    ContainerRandomAccessIterator<generic_value> generic_iterator;

备注

该类型描述可与此模板容器类的泛型接口一起使用的泛型迭代器。

示例

// cliext_deque_generic_iterator.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct a generic container
    cliext::deque<wchar_t>::generic_container^ gc1 = %c1;
    for each (wchar_t elem in gc1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // modify generic and display original
    cliext::deque<wchar_t>::generic_iterator gcit = gc1->begin();
    cliext::deque<wchar_t>::generic_value gcval = *gcit;
    *++gcit = gcval;
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
a b c
a a c

deque::generic_reverse_iterator (STL/CLR)

要与容器的泛型接口一起使用的反向迭代器的类型。

语法

typedef Microsoft::VisualC::StlClr::Generic::
    ReverseRandomAccessIterator<generic_value> generic_reverse_iterator;

备注

该类型描述可与此模板容器类的泛型接口一起使用的泛型反向迭代器。

示例

// cliext_deque_generic_reverse_iterator.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct a generic container
    cliext::deque<wchar_t>::generic_container^ gc1 = %c1;
    for each (wchar_t elem in gc1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // modify generic and display original
    cliext::deque<wchar_t>::generic_reverse_iterator gcit = gc1->rbegin();
    cliext::deque<wchar_t>::generic_value gcval = *gcit;
    *++gcit = gcval;
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
a b c
a c c

deque::generic_value (STL/CLR)

要与容器的泛型接口一起使用的元素的类型。

语法

typedef GValue generic_value;

备注

该类型描述一个 GValue 类型的对象,该对象描述可与此模板容器类的泛型接口一起使用的存储元素值。

示例

// cliext_deque_generic_value.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct a generic container
    cliext::deque<wchar_t>::generic_container^ gc1 = %c1;
    for each (wchar_t elem in gc1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // modify generic and display original
    cliext::deque<wchar_t>::generic_iterator gcit = gc1->begin();
    cliext::deque<wchar_t>::generic_value gcval = *gcit;
    *++gcit = gcval;
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
a b c
a a c

deque::insert (STL/CLR)

在指定的位置添加元素。

语法

iterator insert(iterator where, value_type val);
void insert(iterator where, size_type count, value_type val);
template<typename InIt>
    void insert(iterator where, InIt first, InIt last);
void insert(iterator where,
    System::Collections::Generic::IEnumerable<Value>^ right);

参数

count
要插入的元素数。

first
要插入的范围的开头。

last
要插入的范围的末尾。

right
要插入的枚举。

val
要插入的元素的值。

where
容器中要在其前面插入的位置。

注解

每个成员函数紧跟受控序列中 where 指向的元素之前插入由剩余操作数指定的序列

第一个成员函数插入一个值为 val 的元素,并返回一个指定新插入的元素的迭代器。 使用它在迭代器指定的位置前面插入单个元素。

第二个成员函数插入值 val 的 count 个重复元素。 使用它来插入零个或多个连续元素,这些元素都是同一值的副本。

如果 InIt 是整数类型,则第三个成员函数的行为与 insert(where, (size_type)first, (value_type)last) 相同。 否则,它会插入序列 [first, last)。 使用它来插入从另一个序列复制的零个或多个连续元素。

第四个成员函数插入由 right 指定的序列。 用于插入枚举器所描述的序列。

插入单个元素时,元素副本的数量与插入点与序列近端之间的元素数量呈线性关系。 (在序列的任一端插入一个或多个元素时,不会出现元素副本。)如果 InIt 是输入迭代器,则第三个成员函数将有效地为序列中的每个元素执行一次插入。 否则,在插入 N 个元素时,元素副本的数量与 N 以及插入点和序列近端之间的元素数量呈线性关系。

示例

// cliext_deque_insert.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // insert a single value using iterator
    cliext::deque<wchar_t>::iterator it = c1.begin();
    System::Console::WriteLine("insert(begin()+1, L'x') = {0}",
        *c1.insert(++it, L'x'));
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // insert a repetition of values
    cliext::deque<wchar_t> c2;
    c2.insert(c2.begin(), 2, L'y');
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // insert an iterator range
    it = c1.end();
    c2.insert(c2.end(), c1.begin(), --it);
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // insert an enumeration
    c2.insert(c2.begin(),   // NOTE: cast is not needed
        (System::Collections::Generic::IEnumerable<wchar_t>^)%c1);
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
insert(begin()+1, L'x') = x
a x b c
y y
y y a x b
a x b c y y a x b

deque::iterator (STL/CLR)

受控序列的迭代器的类型。

语法

typedef T1 iterator;

备注

该类型描述了可充当受控序列的随机访问迭代器的未指定类型 T1 的对象。

示例

// cliext_deque_iterator.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    cliext::deque<wchar_t>::iterator it = c1.begin();
    for (; it != c1.end(); ++it)
        System::Console::Write("{0} ", *it);
    System::Console::WriteLine();

    // alter first element and redisplay
    it = c1.begin();
    *it = L'x';
    for (; it != c1.end(); ++it)
        System::Console::Write("{0} ", *it);
    System::Console::WriteLine();
    return (0);
    }
a b c
x b c

deque::operator!= (STL/CLR)

双端队列不等于比较。

语法

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

参数

left
要比较的左容器。

right
要比较的右容器。

备注

运算符函数返回 !(left == right)。 当两个双端队列按元素逐个比较时,你可以使用它来测试 left 的顺序是否与 right 不同

示例

// cliext_deque_operator_ne.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign to a new container
    cliext::deque<wchar_t> c2;
    c2.push_back(L'a');
    c2.push_back(L'b');
    c2.push_back(L'd');

    // display contents " a b d"
    for each (wchar_t elem in c2)
        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

deque::operator(STL/CLR)

访问指定位置处的元素。

语法

reference operator[](size_type pos);

参数

pos
要访问的元素的位置。

备注

成员运算符返回对位置 pos 处的元素的引用。使用它来访问位置已知的元素

示例

// cliext_deque_operator_sub.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c" using subscripting
    for (int i = 0; i < c1.size(); ++i)
        System::Console::Write("{0} ", c1[i]);
    System::Console::WriteLine();

    // change an entry and redisplay
    c1[1] = L'x';
    for (int i = 0; i < c1.size(); ++i)
        System::Console::Write("{0} ", c1[i]);
    System::Console::WriteLine();
    return (0);
    }
a b c
a x c

deque::pop_back (STL/CLR)

删除最后一个元素。

语法

void pop_back();

备注

成员函数删除受控序列的最后一个元素,该元素必须为非空元素。 用于缩短双端队列后面的一个元素。

示例

// cliext_deque_pop_back.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // pop an element and redisplay
    c1.pop_back();
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
a b

deque::pop_front (STL/CLR)

删除第一个元素。

语法

void pop_front();

备注

成员函数删除受控序列的第一个元素,该元素必须为非空元素。 用于缩短双端队列前面的一个元素。

示例

// cliext_deque_pop_front.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // pop an element and redisplay
    c1.pop_front();
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
b c

deque::push_back (STL/CLR)

添加新的最后一个元素。

语法

void push_back(value_type val);

备注

此成员函数在受控序列的末尾插入一个值为 val 的元素。 可用于将另一个元素追加到双端队列中。

示例

// cliext_deque_push_back.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c

deque::push_front (STL/CLR)

添加新的第一个元素。

语法

void push_front(value_type val);

备注

此成员函数在受控序列的开头插入一个值为 val 的元素。 可用于在双端队列前面预置另一个元素。

示例

// cliext_deque_push_front.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_front(L'a');
    c1.push_front(L'b');
    c1.push_front(L'c');

    // display contents " c b a"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
c b a

deque::rbegin (STL/CLR)

指定反向受控序列的开头。

语法

reverse_iterator rbegin();

备注

该成员函数返回一个反向迭代器,指定受控序列的最后一个元素,或刚超出空序列开头的位置。 因此,它指定反向序列的 beginning。 用于获取一个迭代器,该迭代器指定按相反顺序显示的受控序列的 current 开头,但如果受控序列的长度发生更改,则该迭代器的状态也会发生更改。

示例

// cliext_deque_rbegin.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect first two items in reversed sequence
    cliext::deque<wchar_t>::reverse_iterator rit = c1.rbegin();
    System::Console::WriteLine("*rbegin() = {0}", *rit);
    System::Console::WriteLine("*++rbegin() = {0}", *++rit);

    // alter first two items and reinspect
    *--rit = L'x';
    *++rit = L'y';
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
*rbegin() = c
*++rbegin() = b
a y x

deque::reference (STL/CLR)

元素的引用的类型。

语法

typedef value_type% reference;

备注

该类型描述了对元素的引用。

示例

// cliext_deque_reference.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    cliext::deque<wchar_t>::iterator it = c1.begin();
    for (; it != c1.end(); ++it)
        {   // get a reference to an element
        cliext::deque<wchar_t>::reference ref = *it;
        System::Console::Write("{0} ", ref);
        }
    System::Console::WriteLine();

    // modify contents " a b c"
    for (it = c1.begin(); it != c1.end(); ++it)
        {   // get a reference to an element
        cliext::deque<wchar_t>::reference ref = *it;

        ref += (wchar_t)(L'A' - L'a');
        System::Console::Write("{0} ", ref);
        }
    System::Console::WriteLine();
    return (0);
    }
a b c
A B C

deque::rend (STL/CLR)

指定反向受控序列的末尾。

语法

reverse_iterator rend();

备注

该成员函数返回一个反向迭代器,指向刚超出受控序列开头的位置。 因此,它指定反向序列的 end。 用于获取一个迭代器,该迭代器指定按相反顺序显示的受控序列的 current 末尾,但如果受控序列的长度发生更改,则该迭代器的状态也会发生更改。

示例

// cliext_deque_rend.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect first two items
    cliext::deque<wchar_t>::reverse_iterator rit = c1.rend();
    --rit;
    System::Console::WriteLine("*-- --rend() = {0}", *--rit);
    System::Console::WriteLine("*--rend() = {0}", *++rit);

    // alter first two items and reinspect
    *--rit = L'x';
    *++rit = L'y';
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
*-- --rend() = b
*--rend() = a
y x c

deque::resize (STL/CLR)

更改元素数目。

语法

void resize(size_type new_size);
void resize(size_type new_size, value_type val);

参数

new_size
受控序列的新大小。

val
填充元素的值。

注解

这两个成员函数都确保 deque::size (STL/CLR)() 以后返回 new_size。 如果它必须使受控序列更长,则第一个成员函数追加具有值 value_type() 的元素,而第二个成员函数追加具有值 val 的元素。 为了缩短受控序列,这两个成员函数都会有效地擦除最后一个元素 deque::size (STL/CLR)() -new_size 次。 使用它来确保受控序列的大小为 new_size,方法是剪裁或填充当前受控序列

示例

// cliext_deque_resize.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
// construct an empty container and pad with default values
    cliext::deque<wchar_t> c1;
    System::Console::WriteLine("size() = {0}", c1.size());
    c1.resize(4);
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", (int)elem);
    System::Console::WriteLine();

    // resize to empty
    c1.resize(0);
    System::Console::WriteLine("size() = {0}", c1.size());

    // resize and pad
    c1.resize(5, L'x');
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
size() = 0
0 0 0 0
size() = 0
x x x x x

deque::reverse_iterator (STL/CLR)

受控序列的反向迭代器的类型。

语法

typedef T3 reverse_iterator;

备注

该类型描述了可充当受控序列的反向迭代器的未指定类型 T3 的对象。

示例

// cliext_deque_reverse_iterator.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c" reversed
    cliext::deque<wchar_t>::reverse_iterator rit = c1.rbegin();
    for (; rit != c1.rend(); ++rit)
        System::Console::Write("{0} ", *rit);
    System::Console::WriteLine();

    // alter first element and redisplay
    rit = c1.rbegin();
    *rit = L'x';
    for (; rit != c1.rend(); ++rit)
        System::Console::Write("{0} ", *rit);
    System::Console::WriteLine();
    return (0);
    }
c b a
x b a

deque::size (STL/CLR)

对元素数进行计数。

语法

size_type size();

备注

成员函数将返回受控序列的长度。 用于确定受控序列中的当前元素数。 如果只关心序列是否具有非零大小,请参阅 deque::empty (STL/CLR)()

示例

// cliext_deque_size.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    System::Console::WriteLine("size() = {0} starting with 3", c1.size());

    // clear the container and reinspect
    c1.clear();
    System::Console::WriteLine("size() = {0} after clearing", c1.size());

    // add elements and clear again
    c1.push_back(L'a');
    c1.push_back(L'b');
    System::Console::WriteLine("size() = {0} after adding 2", c1.size());
    return (0);
    }
a b c
size() = 3 starting with 3
size() = 0 after clearing
size() = 2 after adding 2

deque::size_type (STL/CLR)

两个元素间的带符号距离的类型。

语法

typedef int size_type;

备注

该类型描述非负元素计数。

示例

// cliext_deque_size_type.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // compute positive difference
    cliext::deque<wchar_t>::size_type diff = c1.end() - c1.begin();
    System::Console::WriteLine("end()-begin() = {0}", diff);
    return (0);
    }
a b c
end()-begin() = 3

deque::swap (STL/CLR)

交换两个容器的内容。

语法

void swap(deque<Value>% right);

参数

right
要与其交换内容的容器。

备注

成员函数交换 *this 和 right 之间的受控序列。 它在常量时间内执行此操作且不引发异常。 你可以将其用作交换两个容器的内容的快捷方式。

示例

// cliext_deque_swap.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct another container with repetition of values
    cliext::deque<wchar_t> c2(5, L'x');
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // swap and redisplay
    c1.swap(c2);
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
x x x x x
x x x x x
a b c

deque::to_array (STL/CLR)

将受控序列复制到新数组。

语法

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

备注

成员函数返回一个包含受控序列的数组。 用于以数组形式获取受控序列的副本。

示例

// cliext_deque_to_array.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // copy the container and modify it
    cli::array<wchar_t>^ a1 = c1.to_array();

    c1.push_back(L'd');
    for each (wchar_t elem in c1)
        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

deque::value_type (STL/CLR)

元素的类型。

语法

typedef Value value_type;

备注

该类型是模板参数 Value 的同义词

示例

// cliext_deque_value_type.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c" using value_type
    for (cliext::deque<wchar_t>::iterator it = c1.begin();
        it != c1.end(); ++it)
        {   // store element in value_type object
        cliext::deque<wchar_t>::value_type val = *it;

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

operator< (deque) (STL/CLR)

双端队列小于比较。

语法

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

参数

left
要比较的左容器。

right
要比较的右容器。

备注

如果对于 !(right[i] < left[i]) 的最低位置 ileft[i] < right[i] 也为 true,则运算符函数返回 true。 否则,它返回 left->size() < right->size()。当两个双端队列按元素逐个比较时,可以用它来测试 left 是否排在 right 之前

示例

// cliext_deque_operator_lt.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign to a new container
    cliext::deque<wchar_t> c2;
    c2.push_back(L'a');
    c2.push_back(L'b');
    c2.push_back(L'd');

    // display contents " a b d"
    for each (wchar_t elem in c2)
        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<= (deque) (STL/CLR)

双端队列小于或等于比较。

语法

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

参数

left
要比较的左容器。

right
要比较的右容器。

注解

运算符函数返回 !(right < left)。 当两个双端队列按元素逐个比较时,你可以使用它来测试 left 是否没有排在 right 之后

示例

// cliext_deque_operator_le.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign to a new container
    cliext::deque<wchar_t> c2;
    c2.push_back(L'a');
    c2.push_back(L'b');
    c2.push_back(L'd');

    // display contents " a b d"
    for each (wchar_t elem in c2)
        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= (deque) (STL/CLR)

替换受控序列。

语法

deque<Value>% operator=(deque<Value>% right);

参数

right
用于复制的容器。

注解

成员运算符将 right 复制到对象,然后返回 *this。 用于将受控序列替换为 right 中的受控序列的副本

示例

// cliext_deque_operator_as.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign to a new container
    cliext::deque<wchar_t> c2;
    c2 = c1;
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
a b c

operator== (deque) (STL/CLR)

双端队列等于比较。

语法

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

参数

left
要比较的左容器。

right
要比较的右容器。

备注

仅当 left 和 right 控制的序列具有相同的长度并且对于每个位置 ileft[i] ==right[i] 时,运算符函数才返回 true。 当两个双端队列按元素逐个比较时,你可以使用它来测试 left 的顺序是否与 right 相同

示例

// cliext_deque_operator_eq.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign to a new container
    cliext::deque<wchar_t> c2;
    c2.push_back(L'a');
    c2.push_back(L'b');
    c2.push_back(L'd');

    // display contents " a b d"
    for each (wchar_t elem in c2)
        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> (deque) (STL/CLR)

双端队列大于比较。

语法

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

参数

left
要比较的左容器。

right
要比较的右容器。

备注

运算符函数返回 right<left。 当两个双端队列按元素逐个比较时,你可以使用它来测试 left 是否排在 right 之后

示例

// cliext_deque_operator_gt.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign to a new container
    cliext::deque<wchar_t> c2;
    c2.push_back(L'a');
    c2.push_back(L'b');
    c2.push_back(L'd');

    // display contents " a b d"
    for each (wchar_t elem in c2)
        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>= (deque) (STL/CLR)

双端队列大于或等于比较。

语法

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

参数

left
要比较的左容器。

right
要比较的右容器。

注解

运算符函数返回 !(left<right)。 当两个双端队列按元素逐个比较时,你可以使用它来测试 left 是否没有排在 right 之前

示例

// cliext_deque_operator_ge.cpp
// compile with: /clr
#include <cliext/deque>

int main()
    {
    cliext::deque<wchar_t> c1;
    c1.push_back(L'a');
    c1.push_back(L'b');
    c1.push_back(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign to a new container
    cliext::deque<wchar_t> c2;
    c2.push_back(L'a');
    c2.push_back(L'b');
    c2.push_back(L'd');

    // display contents " a b d"
    for each (wchar_t elem in c2)
        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