📄 chapter10-39.cpp
字号:
//文件名:CHAPTER10-39.cpp
#include <map>
#include <iostream>
#if _MSC_VER > 1020 // if VC++ version is > 4.2
using namespace std; // std c++ libs implemented in std
#endif
void main( )
{
map <int, int>::allocator_type m1_Alloc;
map <int, int>::allocator_type m2_Alloc;
map <int, double>::allocator_type m3_Alloc;
map <int, int>::allocator_type m4_Alloc;
// The following lines declare objects that use the default allocator.
map <int, int> m1;
map <int, int, allocator<int> > m2;
map <int, double, allocator<double> > m3;
m1_Alloc = m1.get_allocator( );
m2_Alloc = m2.get_allocator( );
m3_Alloc = m3.get_allocator( );
cout << "The number of integers that can be allocated\n"
<< "before free memory is exhausted: "<< m2.max_size( ) << ".\n" << endl;
cout << "The number of doubles that can be allocated\n"
<< "before free memory is exhausted: "<< m3.max_size( ) << ".\n" << endl;
// The following line creates a map m4 with the allocator of map m1.
map <int, int> m4( less<int>( ), m1_Alloc );
m4_Alloc = m4.get_allocator( );
// Two allocators are interchangeable if storage allocated from
//each can be deallocated with the other
if( m1_Alloc == m4_Alloc )
{ cout << "The allocators are interchangeable." << endl; }
else
{ cout << "The allocators are not interchangeable." << endl; }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -