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
    若要插入的項目數目。

  • 第一個
    若要插入範圍的開頭。

  • last
    若要插入範圍的結尾。

  • right
    若要插入的列舉型別。

  • val
    若要插入之項目的值。

  • where
    在之前所要插入容器中的位置。

備註

每個成員函式所指向的項目之前的插入、 where所剩下的運算元,在受控制序列中,指定序列。

第一個成員函式插入具有值的項目val ,並傳回 iterator,指派新插入的項目。您可以用它來插入單一項目之前 iterator 所指定的位置。

第二個成員函式會插入重複的count值的項目val。您可以用它來插入零或多個連續項目也就是相同的值的所有複本。

If InIt is an integer type, the third member function behaves the same as insert(where, (size_type)first, (value_type)last).Otherwise, it inserts the sequence [first, last).您可以用它來插入複製另一個序列中的零或多個相鄰的元素。

第四個成員函式插入所指定的順序right。您可以用它來插入所描述的列舉值的序列。

當插入單一項目,項目列印份數中是以線性的插入點到最接近序列的元素數目。(當序列結尾處插入一個或多個項目,沒有項目複本發生的話。)如果InIt是輸入的 iterator,第三個成員函式有效地執行單一的插入每個項目順序。否則,當插入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); 
    } 
 
  

需求

標頭: < cliext/deque >

Namespace: cliext

請參閱

參考

deque (STL/CLR)

deque::assign (STL/CLR)