mirror of
https://github.com/boostorg/container.git
synced 2025-08-02 22:14:26 +02:00
Added documentation on scoped allocators
[SVN r77679]
This commit is contained in:
@@ -422,10 +422,9 @@ to suppose two allocators of the same type always compare equal (that means that
|
|||||||
by one allocator object could be deallocated by another instance of the same type) and
|
by one allocator object could be deallocated by another instance of the same type) and
|
||||||
allocators were not swapped when the container was swapped.
|
allocators were not swapped when the container was swapped.
|
||||||
|
|
||||||
C++11 further improves stateful allocator support through the
|
C++11 further improves stateful allocator support through
|
||||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2554.pdf
|
[@http://en.cppreference.com/w/cpp/memory/allocator_traits `std::allocator_traits`].
|
||||||
Scoped Allocators model]. [@http://en.cppreference.com/w/cpp/memory/allocator_traits
|
`std::allocator_traits` is the protocol between a container and an allocator, and
|
||||||
`std::allocator_traits`] is the protocol between a container and an allocator, and
|
|
||||||
an allocator writer can customize its behaviour (should the container propagate it in
|
an allocator writer can customize its behaviour (should the container propagate it in
|
||||||
move constructor, swap, etc.?) following `allocator_traits` requirements. [*Boost.Container]
|
move constructor, swap, etc.?) following `allocator_traits` requirements. [*Boost.Container]
|
||||||
not only supports this model with C++11 but also [*backports it to C++03].
|
not only supports this model with C++11 but also [*backports it to C++03].
|
||||||
@@ -437,6 +436,36 @@ not constructed on the fly when auxiliary memory is needed).
|
|||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
|
[section:scoped_allocator Scoped allocators]
|
||||||
|
|
||||||
|
C++11 improves stateful allocators with the introduction of
|
||||||
|
[@http://http://en.cppreference.com/w/cpp/memory/scoped_allocator_adaptor `std::scoped_allocator_adaptor`]
|
||||||
|
class template. `scoped_allocator_adaptor` is instantiated with one outer allocator and zero or more inner
|
||||||
|
allocators.
|
||||||
|
|
||||||
|
A scoped allocator is a mechanism to automatically propagate the state of the allocator to the subobjects
|
||||||
|
of a container in a controlled way. If instantiated with only one allocator type, the inner allocator
|
||||||
|
becomes the `scoped_allocator_adaptor` itself, thus using the same allocator
|
||||||
|
resource for the container and every element within the container and, if the elements themselves are
|
||||||
|
containers, each of their elements recursively. If instantiated with more than one allocator, the first allocator
|
||||||
|
is the outer allocator for use by the container, the second allocator is passed to the constructors of the
|
||||||
|
container's elements, and, if the elements themselves are containers, the third allocator is passed to the
|
||||||
|
elements' elements, and so on.
|
||||||
|
|
||||||
|
[*Boost.Container] implements its own `scoped_allocator_adaptor` class and [*backports this feature also
|
||||||
|
to C++03 compilers]. Due to C++03 limitations, in those compilers
|
||||||
|
the allocator propagation implemented by `scoped_allocator_adaptor::construct` functions
|
||||||
|
will be based on traits([classref boost::container::constructible_with_allocator_suffix constructible_with_allocator_suffix]
|
||||||
|
and [classref boost::container::constructible_with_allocator_prefix constructible_with_allocator_prefix])
|
||||||
|
proposed in [@http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2008/n2554.pdf
|
||||||
|
N2554: The Scoped Allocator Model (Rev 2) proposal]. In conforming C++11 compilers or compilers supporting SFINAE
|
||||||
|
expressions (when `BOOST_NO_SFINAE_EXPR` is NOT defined), traits are ignored and C++11 rules
|
||||||
|
(`is_constructible<T, Args..., inner_allocator_type>::value` and
|
||||||
|
`is_constructible<T, allocator_arg_t, inner_allocator_type, Args...>::value`)
|
||||||
|
will be used to detect if the allocator must be propagated with suffix or prefix allocator arguments.
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
[section:initializer_lists Initializer lists]
|
[section:initializer_lists Initializer lists]
|
||||||
|
|
||||||
[*Boost.Container] does not support initializer lists when constructing or assigning containers
|
[*Boost.Container] does not support initializer lists when constructing or assigning containers
|
||||||
@@ -585,6 +614,21 @@ use [*Boost.Container]? There are several reasons for that:
|
|||||||
|
|
||||||
[section:release_notes Release Notes]
|
[section:release_notes Release Notes]
|
||||||
|
|
||||||
|
[section:release_notes_boost_1_50_00 Boost 1.50 Release]
|
||||||
|
|
||||||
|
* Added Scoped Allocator Model support.
|
||||||
|
|
||||||
|
* Fixed bugs
|
||||||
|
[@https://svn.boost.org/trac/boost/ticket/6566 #6566],
|
||||||
|
[@https://svn.boost.org/trac/boost/ticket/6575 #6575],
|
||||||
|
[@https://svn.boost.org/trac/boost/ticket/6606 #6606],
|
||||||
|
[@https://svn.boost.org/trac/boost/ticket/6615 #6615],
|
||||||
|
[@https://svn.boost.org/trac/boost/ticket/6533 #6533],
|
||||||
|
[@https://svn.boost.org/trac/boost/ticket/6536 #6536],
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
|
||||||
[section:release_notes_boost_1_49_00 Boost 1.49 Release]
|
[section:release_notes_boost_1_49_00 Boost 1.49 Release]
|
||||||
|
|
||||||
* Fixed bugs
|
* Fixed bugs
|
||||||
|
@@ -94,27 +94,27 @@ enum Test
|
|||||||
};
|
};
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{/*
|
||||||
const std::size_t positions_length = 10;
|
{
|
||||||
std::size_t positions[positions_length];
|
const std::size_t positions_length = 10;
|
||||||
vector<int> vector_int;
|
std::size_t positions[positions_length];
|
||||||
vector<int> vector_int2(positions_length);
|
vector<int> vector_int;
|
||||||
for(std::size_t i = 0; i != positions_length; ++i){
|
vector<int> vector_int2(positions_length);
|
||||||
positions[i] = 0u;
|
for(std::size_t i = 0; i != positions_length; ++i){
|
||||||
}
|
positions[i] = 0u;
|
||||||
for(std::size_t i = 0, max = vector_int2.size(); i != max; ++i){
|
}
|
||||||
vector_int2[i] = i;
|
for(std::size_t i = 0, max = vector_int2.size(); i != max; ++i){
|
||||||
}
|
vector_int2[i] = i;
|
||||||
|
}
|
||||||
|
|
||||||
vector_int.insert(vector_int.begin(), 999);
|
vector_int.insert(vector_int.begin(), 999);
|
||||||
|
|
||||||
//vector_int.insert_at_ordered_positions(positions, positions_length, vector_int2.end());
|
vector_int.insert_ordered_at(positions_length, positions + positions_length, vector_int2.end());
|
||||||
|
|
||||||
for(std::size_t i = 0, max = vector_int.size(); i != max; ++i){
|
|
||||||
std::cout << vector_int[i] << std::endl;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
for(std::size_t i = 0, max = vector_int.size(); i != max; ++i){
|
||||||
|
std::cout << vector_int[i] << std::endl;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
recursive_vector_test();
|
recursive_vector_test();
|
||||||
{
|
{
|
||||||
//Now test move semantics
|
//Now test move semantics
|
||||||
|
Reference in New Issue
Block a user