师范街网站建设,最新营销模式有哪些,申请主机网站,统一企业执照信息管理系统提供关于分配器类型的信息
std::allocator_traits template class Alloc struct allocator_traits; (C11 起)
allocator_traits 类模板提供访问分配器 (Allocator) 各种属性的标准化方式。标准容器和其他标准库组件通过此模板访问分配器#xff0c;这使得能以任何类…提供关于分配器类型的信息
std::allocator_traits template class Alloc struct allocator_traits; (C11 起)
allocator_traits 类模板提供访问分配器 (Allocator) 各种属性的标准化方式。标准容器和其他标准库组件通过此模板访问分配器这使得能以任何类类型为分配器只要用户提供的 allocator_traits 特化实现所有要求的功能。 返回分配器所支持的最大对象大小
std::allocator_traitsAlloc::max_size static size_type max_size( const Alloc a ) noexcept; (C11 起)
若可能则通过调用 a.max_size() 从 a 获得最大理论可行的分配大小。
若上述行为不可行例如 a 无成员函数 max_size() 则返回 std::numeric_limitssize_type::max() (C17 前)std::numeric_limitssize_type::max() / sizeof(value_type) (C17 起)
参数
无
返回值
理论最大分配大小 获得复制标准容器后使用的分配器
std::allocator_traitsAlloc::select_on_container_copy_construction static Alloc select_on_container_copy_construction( const Alloc a ); (C11 起)
若可能则获得分配器 a 的赋值构造函数版本通过调用 a.select_on_container_copy_construction() 。若上述不可行例如 a 无成员函数 select_on_container_copy_construction() 则返回不修改的 a 。
此函数为所有标准库容器的复制构造函数所调用。它允许构造函数参数所用的分配器为正在复制的容器所具备并在需要的情况下修改状态。
参数
a-标准容器用以传递给容器复制构造函数的分配器
返回值
复制构造的标准容器所用的分配器。 调用示例
#include iostream
#include memorystruct Cell
{int x;int y;Cell(){std::cout __FUNCTION__;}Cell(int a, int b): x(a), y(b){std::cout __FUNCTION__;}~Cell(){std::cout __FUNCTION__;}bool operator (const Cell cell) const{return x cell.x y cell.y;}bool operator (const Cell cell) const{if (x cell.x){return true;}return y cell.y;}
};std::ostream operator(std::ostream os, const Cell cell)
{os { cell.x , cell.y };return os;
}int main()
{//若可能则通过调用 a.max_size() 从 a 获得最大理论可行的分配大小。//若上述行为不可行例如 a 无成员函数 max_size() //则返回 std::numeric_limitssize_type::max() (C17 前)//std::numeric_limitssize_type::max() / sizeof(value_type) (C17 起)std::allocator_traitsstd::allocatorchar allocator_traitsChar;std::cout std::allocator_traitsstd::allocatorchar max_size: allocator_traitsChar.max_size(std::allocatorint()) std::endl;std::allocator_traitsstd::allocatorint allocator_traitsInt;std::cout std::allocator_traitsstd::allocatorint max_size: allocator_traitsInt.max_size(std::allocatorint()) std::endl;std::allocator_traitsstd::allocatoruint32_t allocator_traitsUInt;std::cout std::allocator_traitsstd::allocatoruint32_t max_size: allocator_traitsUInt.max_size(std::allocatoruint32_t()) std::endl;std::allocator_traitsstd::allocatorlong allocator_traitsLong;std::cout std::allocator_traitsstd::allocatorlong max_size: allocator_traitsLong.max_size(std::allocatorlong()) std::endl;std::allocator_traitsstd::allocatordouble allocator_traitsDouble;std::cout std::allocator_traitsstd::allocatordouble max_size: allocator_traitsDouble.max_size(std::allocatordouble()) std::endl;std::allocator_traitsstd::allocatorCell allocator_traitsCell;std::cout std::allocator_traitsstd::allocatorCell max_size: allocator_traitsCell.max_size(std::allocatorCell()) std::endl;return 0;
}
输出
std::allocator_traitsstd::allocatorchar max_size: 4294967295
std::allocator_traitsstd::allocatorint max_size: 1073741823
std::allocator_traitsstd::allocatoruint32_t max_size: 1073741823
std::allocator_traitsstd::allocatorlong max_size: 1073741823
std::allocator_traitsstd::allocatordouble max_size: 536870911
std::allocator_traitsstd::allocatorCell max_size: 536870911