首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::scoped_allocator_adaptor

Defined in header <scoped_allocator>

?

?

template< class OuterAlloc, class... InnerAlloc > class scoped_allocator_adaptor : public OuterAlloc;

?

(since C++11)

std::scoped_allocator_adaptor类模板是一个分配器,它可以与多级容器%28向量、映射元组列表的集合等一起使用。它是用一个外部分配器类型实例化的。OuterAlloc和零或多个内部分配器类型InnerAlloc....直接用scoped_allocator_adaptor使用OuterAlloc若要分配其元素,但如果元素本身是容器,则使用第一个内部分配器。该容器的元素,如果它们本身就是容器,使用第二个内部分配器,等等。如果容器的级别比内部分配器多,那么最后一个内部分配器将被重用到所有进一步嵌套的容器中。

为了...的目的scoped_allocator_adaptor,如果下一个内部分配器是A,任何阶级T对此std::uses_allocator<T,A>::value==true参与递归,就好像它是一个容器。此外,std::pair的特定重载处理为这样一个容器。scoped_allocator_adaptor::construct...

典型实现持有std::scoped_allocator_adaptor<InnerAllocs...>作为成员对象。

成员类型

Type

Definition

outer_allocator_type

OuterAlloc

inner_allocator_type

scoped_allocator_adaptor<InnerAllocs...> or, if sizeof...(InnerAllocs) == 0, scoped_allocator_adaptor<OuterAlloc>

value_type

std::allocator_traits<OuterAlloc>::value_type

size_type

std::allocator_traits<OuterAlloc>::size_type

difference_type

std::allocator_traits<OuterAlloc>::difference_type

pointer

std::allocator_traits<OuterAlloc>::pointer

const_pointer

std::allocator_traits<OuterAlloc>::const_pointer

void_pointer

std::allocator_traits<OuterAlloc>::void_pointer

const_void_pointer

std::allocator_traits<OuterAlloc>::const_void_pointer

传播[医]上[医]集装箱[医]复制[医]任务STD::真[医]输入if std::分配器[医]性状<A>*宣传[医]上[医]集装箱[医]复制[医]

传播[医]上[医]集装箱[医]移动[医]任务STD::真[医]输入if std::分配器[医]性状<A>*宣传[医]上[医]集装箱[医]移动[医]任务:在Outeralloc和Inneralloc之间至少有一个分配器A的值为真。

传播[医]上[医]集装箱[医]SWAP STD::true[医]输入if std::分配器[医]性状<A>*宣传[医]上[医]集装箱[医]交换:值是对至少一个分配器A在Outeralloc和Inneralloc之间。

是[医]总[医]等于%28C++17%29 std::true[医]输入if std::分配器[医]性状<A>*IS[医]总[医]===

重新绑定模板<class T>结构重新绑定{ty胡枝子f作用域分配器[医]适配器<std::分配程序[医]性状<OuterAlloc>*模板重新绑定[医]异种<T>,InnerAllocs...>Other;};

成员函数

(constructor)

creates a new scoped_allocator_adaptor instance (public member function)

(destructor)

destructs a scoped_allocator_adaptor instance (public member function)

operator=

assigns a scoped_allocator_adaptor (public member function)

inner_allocator

obtains an inner_allocator reference (public member function)

outer_allocator

obtains an outer_allocator reference (public member function)

allocate

allocates uninitialized storage using the outer allocator (public member function)

deallocate

deallocates storage using the outer allocator (public member function)

max_size

returns the largest allocation size supported by the outer allocator (public member function)

construct

constructs an object in allocated storage, passing the inner allocator to its constructor if appropriate (public member function)

destroy

destructs an object in allocated storage (public member function)

select_on_container_copy_construction

copies the state of scoped_allocator_adaptor and all its allocators (public member function)

非会员职能

operator==operator!=

compares two scoped_allocator_adaptor instances (public member function)

二次

代码语言:javascript
复制
#include <vector>
#include <scoped_allocator>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/allocators/adaptive_pool.hpp>
namespace bi = boost::interprocess;
template<class T> using alloc = bi::adaptive_pool<T,
                                    bi::managed_shared_memory::segment_manager>;
using ipc_row = std::vector<int, alloc<int>>;
using ipc_matrix = std::vector<ipc_row, std::scoped_allocator_adaptor<alloc<ipc_row>>>;
int main ()
{
   bi::managed_shared_memory s(bi::create_only, "Demo", 65536);
   alloc<int> a(s.get_segment_manager());
 
   // create vector of vectors in shared memory
   ipc_matrix v(a);   // note: rebinds alloc<ipc_row> from this alloc<int>
 
   // for all these additions, the inner vectors obtain their allocator arguments
   // from the outer vector's scoped_allocator_adaptor
   v.resize(1); v[0].push_back(1);
   v.emplace_back(2);
   std::vector<int> local_row = {1,2,3};
   v.emplace_back(local_row.begin(), local_row.end());
 
   bi::shared_memory_object::remove("Demo");
}

二次

另见

allocator_traits (C++11)

provides information about allocator types (class template)

uses_allocator (C++11)

checks if the specified type supports uses-allocator construction (class template)

allocator

the default allocator (class template)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com