C++ 概念: Allocator

来自cppreference.com
< cpp‎ | concept

封装内存分配和释放策略.
原文:
Encapsulates memory allocation and deallocation strategy.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
每一个标准库组件,可能需要分配或释放存储,从std::stringstd::vector,和每一个容器除了std::array,以std::shared_ptrstd::function,通过Allocator:满足以下要求的类类型的对象.....
原文:
Every standard library component that may need to allocate or release storage, from std::string, std::vector, and every container except std::array, to std::shared_ptr and std::function, does so through an Allocator: an object of a class type that satisfies the following requirements.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
有些要求是可选的:模板std::allocator_traits提供的默认实现所有可选的要求,和所有的标准库容器和其他分配器感知类访问的分配器通过std::allocator_traits,而不是直接.
原文:
Some requirements are optional: the template std::allocator_traits supplies the default implementations for all optional requirements, and all standard library containers and other allocator-aware classes access the allocator through std::allocator_traits, not directly.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 要求

鉴于
原文:
Given
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • A,的分配器类型T
    原文:
    A, an Allocator for type T
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • B,相同类型U分配器
    原文:
    B, the same Allocator for type U
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • ptrallocator_traits<A>::pointer类型的值,通过调用allocator_traits<A>::allocate()
    原文:
    ptr, a value of type allocator_traits<A>::pointer, obtained by calling allocator_traits<A>::allocate()
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • cptrallocator_traits<A>::const_pointer类型的值,得到的转换,从ptr
    原文:
    cptr, a value of type allocator_traits<A>::const_pointer, obtained by conversion from ptr
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • vptrallocator_traits<A>::void_pointer类型的值,得到的转换,从ptr
    原文:
    vptr, a value of type allocator_traits<A>::void_pointer, obtained by conversion from ptr
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • cvptr,值类型allocator_traits<A>::const_void_pointer,得到的转换cptrvptr
    原文:
    cvptr, a value of type allocator_traits<A>::const_void_pointer, obtained by conversion from cptr or from vptr
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • xptr的dereferencable的指针某种类型X
    原文:
    xptr, a dereferencable pointer to some type X
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
Expression Requirements Return type
A::pointer (可选的) Satisfies NullablePointer and RandomAccessIterator
A::const_pointer (可选的) A::pointer is convertible to A::const_pointer. Satisfies NullablePointer and RandomAccessIterator
A::void_pointer (可选的) A::pointer is convertible to A::void_pointer
B::void_pointerA::void_pointer是相同的类型。满足NullablePointer
原文:
B::void_pointer and A::void_pointer are the same type. Satisfies NullablePointer
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
A::const_void_pointer (可选的) A::pointer, A::const_pointer, and A::void_pointer are convertible to A::const_void_pointer
B::const_void_pointerA::const_void_pointer是相同的类型。满足NullablePointer
原文:
B::const_void_pointer and A::const_void_pointer are the same type. Satisfies NullablePointer
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
A::value_type the type T
A::size_type (可选的) A::size_type can represent the size of the largest object A can allocate unsigned integer type
A::difference_type (可选的) A::difference_type can represent the difference of any two pointers to the objects allocated by A signed integer type
A::template rebind<U>::other (可选的[1]) for any U, B::template rebind<T>::other is A the type B
*ptr T&
*cptr *cptr and *ptr identify the same object const T&
ptr->m same as (*ptr).m, if (*ptr).m is well-defined the type of T::m
cptr->m same as (*cptr).m, if (*cptr).m is well-defined the type of T::m
static_cast<A::pointer>(vptr) static_cast<A::pointer>(vptr) == ptr A::pointer
static_cast<A::const_pointer>(cvptr) static_cast<A::const_pointer>(vptr) == cptr A::const_pointer
a.allocate(n) allocates storage suitable for n objects of type T, but does not construct them. May throw exceptions. A::pointer
a.allocate(n, cptr) (可选的) same as a.allocate(n), but may use cptr in unspecified manner to aid locality A::pointer
a.deallocate(ptr, n) deallocates storage previously allocated by a call to a.allocate(n). Does not call destructors, if any objects were constructed, they must be destroyed before calling a.deallocate(). Does not throw exceptions. (not used)
a.max_size() (可选的) the largest value that can be passed to A::allocate() A::size_type
a1 == a2 returns true only if the storage allocated by the allocator a1 can be deallocated through a2. Establishes reflexive, symmetric, and transitive relationship. Does not throw exceptions. bool
a1 != a2 same as !(a1==a2) bool
A a1(a) Copy-constructs a1 such that a1 == a. Does not throw exceptions.
A a(b) Constructs a such that B(a)==b and A(b)==a. Does not throw exceptions.
A a1(std::move(a)) Constructs a1 such that it equals the prior value of a. Does not throw exceptions.
A a(std::move(b)) Constructs a such that it equals the prior value of A(b). Does not throw exceptions.
a.construct(xptr, args) (可选的) Constructs an object of type X in previously-allocated storage at the address pointed to by xptr, using args as the constructor arguments
a.destroy(xptr) (可选的) Destructs an object of type X pointed to by xptr, but does not deallocate any storage.
a.select_on_container_copy_construction() (可选的) Provides an instance of A to be used by the container that is copy-constructed from the one that uses a currently. Usually returns either a copy of a or a default-constructed A(). A
a.propagate_on_container_copy_assignment (可选的) true if the allocator of type A needs to be copied when the container that uses it is copy-assigned std::true_type or std::false_type or derived from such
a.propagate_on_container_move_assignment (可选的) true if the allocator of type A needs to be copied when the container that uses it is move-assigned std::true_type or std::false_type or derived from such
a.propagate_on_container_swap (可选的) true if the allocators of type A need to be swapped when two containers that use them are swapped std::true_type or std::false_type or derived from such
注意事项:
原文:
Notes:
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
[1]重新绑定是唯一可选的(提供由std :: allocator_traits),如果这分配器模板的形式SomeAllocator的,<T, Args>,args是零个或多个额外的模板参数.
原文:
[1] rebind is only optional (provided by std::allocator_traits) if this allocator is a template of the form SomeAllocator<T, Args>, where Args is zero or more additional template parameters.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里