Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54434 - sandbox/monotonic/libs/monotonic/test/clones
From: christian.schladetsch_at_[hidden]
Date: 2009-06-28 02:11:31


Author: cschladetsch
Date: 2009-06-28 02:11:30 EDT (Sun, 28 Jun 2009)
New Revision: 54434
URL: http://svn.boost.org/trac/boost/changeset/54434

Log:
added make_cloneable_allocator
Text files modified:
   sandbox/monotonic/libs/monotonic/test/clones/main.cpp | 48 ++++++++++++++++++++++++++++++++++++++-
   1 files changed, 46 insertions(+), 2 deletions(-)

Modified: sandbox/monotonic/libs/monotonic/test/clones/main.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/clones/main.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/clones/main.cpp 2009-06-28 02:11:30 EDT (Sun, 28 Jun 2009)
@@ -34,6 +34,48 @@
         explicit derived2(std::string const &n) : str(n) { }
 };
 
+namespace detail2
+{
+ template <class Alloc>
+ struct cloneable_allocator : Alloc, boost::abstract_allocator
+ {
+ typedef typename Alloc::template rebind<char>::other CharAlloc;
+
+ boost::abstract_allocator::pointer allocate_bytes(size_t num_bytes, size_t alignment)
+ {
+ CharAlloc alloc;
+ // todo: alignment; this is done already for monotonic, copy that here
+ return alloc.allocate(num_bytes);
+ }
+
+ void deallocate_bytes(boost::abstract_allocator::pointer ptr)
+ {
+ CharAlloc alloc;
+ alloc.deallocate(ptr, 1);
+ }
+ };
+
+ template <class Alloc, bool>
+ struct make_cloneable_allocator
+ {
+ typedef cloneable_allocator<Alloc> type;
+ };
+
+ template <class Alloc>
+ struct make_cloneable_allocator<Alloc, true>
+ {
+ typedef Alloc type;
+ };
+}
+
+template <class Alloc>
+struct make_cloneable_allocator
+{
+ typedef boost::is_convertible<Alloc *, boost::abstract_allocator *> is_convertible;
+ BOOST_STATIC_CONSTANT(bool, is_cloneable = is_convertible::value);
+ typedef typename detail2::make_cloneable_allocator<Alloc, is_cloneable>::type type;
+};
+
 /*
 
 namespace boost { namespace ptr_container {
@@ -48,11 +90,13 @@
 
 int main()
 {
- typedef ptr_vector<cloneable::common_base, cloneable::allocator, monotonic::allocator<int> > vec;
+ //typedef make_cloneable_allocator<std::allocator<int> >::type alloc_type;
+ typedef make_cloneable_allocator<monotonic::allocator<int> >::type alloc_type;
+ typedef ptr_vector<cloneable::common_base, cloneable::allocator, alloc_type > vec;
 
         {
                 vec bases;
- BOOST_ASSERT(bases.get_allocator().get_storage() == &monotonic::static_storage<>::get_storage());
+// BOOST_ASSERT(bases.get_allocator().get_storage() == &monotonic::static_storage<>::get_storage());
 
                 //! bases.push_back(new derived(42)); // this doesn't use the custom allocator!
                 //! derived *obj = bases.get_allocator().allocate(1); // this has to be recast


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