构造为空或是其他某些基于全部或部分的副本的基于。
multimap( );
explicit multimap(
const Traits& _Comp
);
multimap(
const Traits& _Comp,
const Allocator& _Al
);
map(
const multimap& _Right
);
template<class InputIterator>
multimap(
InputIterator _First,
InputIterator _Last
);
template<class InputIterator>
multimap(
InputIterator _First,
InputIterator _Last,
const Traits& _Comp
);
template<class InputIterator>
multimap(
InputIterator _First,
InputIterator _Last,
const Traits& _Comp,
const Allocator& _Al
);
multimap(
multimap&& _Right
);
参数
Parameter |
说明 |
_Al |
为此基于对象将使用的存储为程序选件类,默认为分配器。 |
_Comp |
类型 const使用的Traits 的比较函数按映射的元素,默认为 Traits。 |
_Right |
构造的设置是复制的映射。 |
_First |
第一个元素的位置在要复制的元素范围内。 |
_Last |
第一个元素的位置在要复制的元素范围的。 |
备注
所有构造函数存储的分配器对象的类型管理基于的内存存储,并且可以通过调用 get_allocator之后返回。分配器参数在所使用的选件类声明和预处理器宏通常忽略替换替换分配器。
所有构造函数初始化它们的基于。
所有构造函数存储用于在基于键的中一个命令,并可通过调用 key_comp后返回类型 Traits 的函数对象。
指定空的初始基于,第二个参数指定比较函数(_Comp)的类型用于建立元素和第三的顺序显式指定分配器类型(_Al)的前三个构造函数是使用。关键字 explicit 禁止某些类型的自动类型转换。
第四个构造函数指定基于 _Right的副本。
接下来的三个构造函数复制范围[_First,_Last)的映射随着在指定选件类 Traits 和分配器的比较函数的类型的显式的增加。
最后一个构造函数由移动的 _Right指定基于的副本。
示例
// multimap_ctor.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
int main( )
{
using namespace std;
typedef pair <int, int> Int_Pair;
multimap <int, int>::iterator m1_Iter, m3_Iter, m4_Iter, m5_Iter, m6_Iter, m7_Iter;
multimap <int, int, greater<int> >::iterator m2_Iter;
// Create an empty multimap m0 of key type integer
multimap <int, int> m0;
// Create an empty multimap m1 with the key comparison
// function of less than, then insert 4 elements
multimap <int, int, less<int> > m1;
m1.insert( Int_Pair( 1, 10 ) );
m1.insert( Int_Pair( 2, 20 ) );
m1.insert( Int_Pair( 3, 30 ) );
m1.insert( Int_Pair( 4, 40 ) );
// Create an empty multimap m2 with the key comparison
// function of geater than, then insert 2 elements
multimap <int, int, greater<int> > m2;
m2.insert( Int_Pair( 1, 10 ) );
m2.insert( Int_Pair( 2, 20 ) );
// Create a multimap m3 with the
// allocator of multimap m1
multimap <int, int>::allocator_type m1_Alloc;
m1_Alloc = m1.get_allocator( );
multimap <int, int> m3( less<int>( ), m1_Alloc );
m3.insert( Int_Pair( 3, 30 ) );
// Create a copy, multimap m4, of multimap m1
multimap <int, int> m4( m1 );
// Create a multimap m5 by copying the range m1[_First, _Last)
multimap <int, int>::const_iterator m1_bcIter, m1_ecIter;
m1_bcIter = m1.begin( );
m1_ecIter = m1.begin( );
m1_ecIter++;
m1_ecIter++;
multimap <int, int> m5( m1_bcIter, m1_ecIter );
// Create a multimap m6 by copying the range m4[_First, _Last)
// and with the allocator of multimap m2
multimap <int, int>::allocator_type m2_Alloc;
m2_Alloc = m2.get_allocator( );
multimap <int, int> m6(m4.begin( ), ++m4.begin( ), less<int>( ), m2_Alloc);
cout << "m1 =";
for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )
cout << " " << m1_Iter -> second;
cout << endl;
cout << "m2 =";
for ( m2_Iter = m2.begin( ); m2_Iter != m2.end( ); m2_Iter++ )
cout << " " << m2_Iter -> second;
cout << endl;
cout << "m3 =";
for ( m3_Iter = m3.begin( ); m3_Iter != m3.end( ); m3_Iter++ )
cout << " " << m3_Iter -> second;
cout << endl;
cout << "m4 =";
for ( m4_Iter = m4.begin( ); m4_Iter != m4.end( ); m4_Iter++ )
cout << " " << m4_Iter -> second;
cout << endl;
cout << "m5 =";
for ( m5_Iter = m5.begin( ); m5_Iter != m5.end( ); m5_Iter++ )
cout << " " << m5_Iter -> second;
cout << endl;
cout << "m6 =";
for ( m6_Iter = m6.begin( ); m6_Iter != m6.end( ); m6_Iter++ )
cout << " " << m6_Iter -> second;
cout << endl;
// Create a map m7 by moving m5
cout << "m7 =";
map<int, int> m7(move(m5));
for ( m7_Iter = m7.begin( ); m7_Iter != m7.end( ); m7_Iter++ )
cout << " " << m7_Iter -> second;
cout << endl;
}
Output
m1 = 10 20 30 40
m2 = 20 10
m3 = 30
m4 = 10 20 30 40
m5 = 10 20
m6 = 10
m7 = 10 20
要求
标头: <map>
命名空间: std