Subject: [Boost-bugs] [Boost C++ Libraries] #1996: "void" template specialisation for the pool allocators
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-06-07 16:24:04
#1996: "void" template specialisation for the pool allocators
--------------------------+-------------------------------------------------
Reporter: Armin Felke | Owner: no-maintainer
Type: Patches | Status: new
Milestone: Boost 1.35.1 | Component: pool
Version: Boost 1.35.0 | Severity: Optimization
Keywords: |
--------------------------+-------------------------------------------------
It might be reasonable to add a template specialisation for the allocator
classes "pool_allocator<T,..>" and "fast_pool_allocator<T,..>" with
T=void?
The library boost::multi_index, e.g., currently (version 1.35.0) uses the
allocator<void> notation in its generic code (expecting a "default
allocator").
In section 20.4.1 [lib.default.allocator] of the C++ standard the
following specialisation is defined for class std::allocator as follows:
<code>
template <class T> class allocator;
// specialize for void:
template <> class allocator<void> {
public:
typedef void* pointer;
typedef const void* const_pointer;
// reference-to-void members are impossible.
typedef void value_type;
template <class U> struct rebind { typedef allocator<U> other; };
};
</code>
In order to use the pool allocators with multi_index_container and ease
generic programming, I would suggest the following additions to
pool_alloc.hpp:
<code>
template<
typename UserAllocator,
typename Mutex,
unsigned NextSize>
class pool_allocator<void, UserAllocator, Mutex, NextSize> {
public:
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
template <class U> struct rebind {
typedef pool_allocator<U, UserAllocator, Mutex, NextSize> other;
};
};
template<
typename UserAllocator,
typename Mutex,
unsigned NextSize>
class fast_pool_allocator<void, UserAllocator, Mutex, NextSize> {
public:
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
template <class U> struct rebind {
typedef fast_pool_allocator<U, UserAllocator, Mutex, NextSize>
other;
};
};
</code>
Best regards
Armin Felke
--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1996>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:58 UTC