Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54007 - in sandbox/monotonic: boost/monotonic libs/monotonic/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-17 05:35:30


Author: cschladetsch
Date: 2009-06-17 05:35:28 EDT (Wed, 17 Jun 2009)
New Revision: 54007
URL: http://svn.boost.org/trac/boost/changeset/54007

Log:
added detail::Construct
Text files modified:
   sandbox/monotonic/boost/monotonic/allocator.hpp | 47 +++++++++++++++++++++++++++++----------
   sandbox/monotonic/libs/monotonic/test/main.cpp | 4 +-
   2 files changed, 37 insertions(+), 14 deletions(-)

Modified: sandbox/monotonic/boost/monotonic/allocator.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/allocator.hpp (original)
+++ sandbox/monotonic/boost/monotonic/allocator.hpp 2009-06-17 05:35:28 EDT (Wed, 17 Jun 2009)
@@ -31,6 +31,39 @@
                         };
                 };
 
+ namespace detail
+ {
+ template <bool is_mono_container>
+ struct Construct
+ {
+ template <class T, class Alloc>
+ static void Given(T *ptr, Alloc *allocator)
+ {
+ new (ptr) T();
+ }
+ template <class T, class Alloc>
+ static void Given(T *ptr, T const &val, Alloc *allocator)
+ {
+ new (ptr) T(val);
+ }
+ };
+ template <>
+ struct Construct<true>
+ {
+ template <class T, class Alloc>
+ static void Given(T *ptr, Alloc *allocator)
+ {
+ new (ptr) T(*allocator);
+ }
+ template <class T, class Alloc>
+ static void Given(T *ptr, T const &val, Alloc *allocator)
+ {
+ new (ptr) T(*allocator);
+ *ptr = val;
+ }
+ };
+ }
+
                 template <class T>
                 struct allocator
                 {
@@ -109,22 +142,12 @@
 
                         void construct(pointer ptr)
                         {
- construct(ptr, detail::IsMonotonic<T>());
- }
-
- void construct(pointer ptr, const boost::false_type &)
- {
- new (ptr) value_type();
- }
-
- void construct(pointer ptr, const boost::true_type &)
- {
- new (ptr) value_type(*this);
+ detail::Construct<detail::IsMonotonic<T>::value>::Given(ptr, this);
                         }
 
                         void construct(pointer ptr, const T& val)
                         {
- new (ptr) value_type(val);
+ detail::Construct<detail::IsMonotonic<T>::value>::Given(ptr, val, this);
                         }
 
                         void destroy(pointer ptr)

Modified: sandbox/monotonic/libs/monotonic/test/main.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/main.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/main.cpp 2009-06-17 05:35:28 EDT (Wed, 17 Jun 2009)
@@ -370,8 +370,8 @@
         _set_se_translator(straight_to_debugger);
 #endif
 
- //test_mono_map();
- test_map_list_heap_stack();
+ test_mono_map();
+ //test_map_list_heap_stack();
         //test_static_storage();
         //run_all_tests();
 }


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