Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77679 - in trunk/libs/container: doc test
From: igaztanaga_at_[hidden]
Date: 2012-03-31 16:57:46


Author: igaztanaga
Date: 2012-03-31 16:57:45 EDT (Sat, 31 Mar 2012)
New Revision: 77679
URL: http://svn.boost.org/trac/boost/changeset/77679

Log:
Added documentation on scoped allocators
Text files modified:
   trunk/libs/container/doc/container.qbk | 52 ++++++++++++++++++++++++++++++++++++---
   trunk/libs/container/test/vector_test.cpp | 42 ++++++++++++++++----------------
   2 files changed, 69 insertions(+), 25 deletions(-)

Modified: trunk/libs/container/doc/container.qbk
==============================================================================
--- trunk/libs/container/doc/container.qbk (original)
+++ trunk/libs/container/doc/container.qbk 2012-03-31 16:57:45 EDT (Sat, 31 Mar 2012)
@@ -422,10 +422,9 @@
 by one allocator object could be deallocated by another instance of the same type) and
 allocators were not swapped when the container was swapped.
 
-C++11 further improves stateful allocator support through the
-[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2554.pdf
-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
+C++11 further improves stateful allocator support through
+[@http://en.cppreference.com/w/cpp/memory/allocator_traits `std::allocator_traits`].
+`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
 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].
@@ -437,6 +436,36 @@
 
 [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]
 
 [*Boost.Container] does not support initializer lists when constructing or assigning containers
@@ -585,6 +614,21 @@
 
 [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]
 
 * Fixed bugs

Modified: trunk/libs/container/test/vector_test.cpp
==============================================================================
--- trunk/libs/container/test/vector_test.cpp (original)
+++ trunk/libs/container/test/vector_test.cpp 2012-03-31 16:57:45 EDT (Sat, 31 Mar 2012)
@@ -94,27 +94,27 @@
 };
 
 int main()
-{
- const std::size_t positions_length = 10;
- std::size_t positions[positions_length];
- vector<int> vector_int;
- vector<int> vector_int2(positions_length);
- 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;
- }
-
- vector_int.insert(vector_int.begin(), 999);
-
- //vector_int.insert_at_ordered_positions(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;
-
+{/*
+ {
+ const std::size_t positions_length = 10;
+ std::size_t positions[positions_length];
+ vector<int> vector_int;
+ vector<int> vector_int2(positions_length);
+ 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;
+ }
+
+ vector_int.insert(vector_int.begin(), 999);
+
+ 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;
+ }
+ }*/
    recursive_vector_test();
    {
       //Now test move semantics


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk