共用方式為


list::splice

移除引數清單中的項目並將它們插入至目標清單。

void splice(
   iterator _Where,
   list<Type, Allocator>& _Right
);
void splice(
   iterator _Where,
   list<Type, Allocator>& _Right,
   iterator _First
);
void splice(
   iterator _Where,
   list<Type, Allocator>& _Right,
   iterator _First,
   iterator _Last
);

參數

  • _Where
    在目前的引數清單項目將插入的目標清單的位置。

  • _Right
    要插入目標清單的引數清單。

  • _First
    在從引數清單中插入的範圍中第一個項目。

  • _Last
    在從引數清單中插入的範圍的第一個項目。

備註

第 10% 成員函式在項目前面插入在引數清單中的所有項目 _Where 位於目標清單。 從引數清單中移除所有項目。

,要在目標清單的項目會指向由 _Where之前,第二 + 成成員函式移除項目指向在引數清單中 _First 並將其插入。

第三 + 成成員函式插入從引數清單中所指定的 [_First, _Last) 範圍,在目標清單的項目會指向由 _Where之前。 從引數清單同時移除插入的範圍。

在所有情況下,指向在要連接之項目的 Iterator 或參考就會變成無效。

範例

// list_splice.cpp
// compile with: /EHsc
#include <list>
#include <iostream>

int main( )
{
   using namespace std;
   list <int> c1, c2, c3, c4;
   list <int>::iterator c1_Iter, c2_Iter, w_Iter, f_Iter, l_Iter;
   
   c1.push_back( 10 );
   c1.push_back( 11 );
   c2.push_back( 12 );
   c2.push_back( 20 );
   c2.push_back( 21 );
   c3.push_back( 30 );
   c3.push_back( 31 );
   c4.push_back( 40 );
   c4.push_back( 41 );
   c4.push_back( 42 );

   cout << "c1 =";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;

   cout << "c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;

   w_Iter = c2.begin( );
   w_Iter++;
   c2.splice( w_Iter,c1 );
   cout << "After splicing c1 into c2: c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;

   f_Iter = c3.begin( );
   c2.splice( w_Iter,c3, f_Iter );
   cout << "After splicing the first element of c3 into c2: c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;

   f_Iter = c4.begin( );
   l_Iter = c4.end( );
   l_Iter--;
   c2.splice( w_Iter,c4, f_Iter, l_Iter );
   cout << "After splicing a range of c4 into c2: c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;
}
  

需求

標題: <list>

命名空間: std

請參閱

參考

list Class

標準樣板程式庫