STL容器使用中的拷贝成本
来源:互联网 发布:sql union limit 编辑:程序博客网 时间:2024/06/03 02:10
#include "stdafx.h"
#include <map>
#include <vector>
#include <list>
using namespace std;
//User Defined Object:
class CustomerObj
{
public:
CustomerObj():m_iObjValue(0)
{
printf("Object (0)->Default Construct!/n");
}
CustomerObj( int iValue ):m_iObjValue(iValue)
{
printf("Object (%d)->User define Construct!/n", m_iObjValue );
}
~CustomerObj()
{
printf( "Object (%d)->Destruct/n", m_iObjValue );
}
CustomerObj(const CustomerObj& obj )
{
m_iObjValue = obj.m_iObjValue;
printf( "Obect (%d)->Copy Construct!/n", m_iObjValue );
}
CustomerObj& operator=(const CustomerObj& obj)
{
m_iObjValue = obj.m_iObjValue;
printf( "Object (%d)->Copy assignment/n", m_iObjValue );
return *this;
}
void SetObjValue( int iValue )
{
m_iObjValue = iValue;
}
int GetObjValue()
{
return m_iObjValue;
}
private:
int m_iObjValue;
};
//A function template to test the sequence container
template< class T >
void SEQ_Copy_Cost_Test( T TestContainer )
{
CustomerObj myObject;
printf( "push_back:(%d).>>>>>>>>/n", myObject.GetObjValue() );
TestContainer.push_back( myObject );
myObject.SetObjValue( 1 );
printf( "push_back:(%d).>>>>>>>>/n", myObject.GetObjValue() );
TestContainer.push_back( myObject );
myObject.SetObjValue( 2 );
printf( "push_back:(%d).>>>>>>>>/n", myObject.GetObjValue() );
TestContainer.push_back( myObject );
myObject.SetObjValue( 3 );
printf( "push_back:(%d).>>>>>>>>/n", myObject.GetObjValue() );
TestContainer.push_back( myObject );
myObject.SetObjValue( 4 );
printf( "push_back:(%d).>>>>>>>>/n", myObject.GetObjValue() );
TestContainer.push_back( myObject );
myObject.SetObjValue( 5 );
printf("insert:(%d) at begining.>>>>>>>>/n", myObject.GetObjValue() );
TestContainer.insert( TestContainer.begin(), myObject );
printf("pop_back.>>>>>>>>/n");
TestContainer.pop_back();
}
int _tmain(int argc, _TCHAR* argv[])
{
//Vector Container
printf("Vector Container:>>>>>>>/n");
vector< CustomerObj > VectorContainer;
SEQ_Copy_Cost_Test( VectorContainer );
//List Container
printf("List Container:>>>>>>>/n");
list< CustomerObj > ListContainer;
SEQ_Copy_Cost_Test( ListContainer );
}
- STL容器使用中的拷贝成本
- 浅谈STL中的容器
- STL中的list容器
- STL中的容器
- STL中的list容器
- STL中的deque容器
- STL中的容器
- STL中的set容器
- STL中的map容器
- STL中的容器对比
- STL 中的容器们
- STL中的set容器
- STL中的容器
- STL 中的通用容器
- STL中的容器
- C++STL中的容器
- STL中的无序容器
- 在使用STL容器时避免使用具有复杂拷贝构造函数的类
- POJ 2115 C Looooops
- 使用Smarty过滤不安全函数
- XFire与Axis 2比较
- TPL脚本语言
- POJ 3204 Ikki's Story I - Road Reconstruction
- STL容器使用中的拷贝成本
- MFC的CArchive类
- ddfda
- 朋友,你好!
- zendstudio文件编码修改问题
- 减少oracle sql回表次数 提高SQL查询性能
- PHP FFMPEG 生成视频缩略图
- 小议 java:comp/env
- Windows XP PXE Server 安装 Redhat AS 5.3_by Ivan-blog