Boost logo

Boost-Commit :

From: xushiweizh_at_[hidden]
Date: 2008-04-30 14:53:04


Author: xushiwei
Date: 2008-04-30 14:53:03 EDT (Wed, 30 Apr 2008)
New Revision: 44939
URL: http://svn.boost.org/trac/boost/changeset/44939

Log:
issue #1879:
1. change class name: stl_alloc -> stl_allocator
2. partially specialize stl_allocator
Text files modified:
   sandbox/memory/boost/memory.hpp | 57 ++++++++++++++++++++++++++++++---------
   sandbox/memory/boost/memory/basic.hpp | 12 ++++++++
   sandbox/memory/libs/memory/test/memory/stl_containers.cpp | 8 ++--
   3 files changed, 60 insertions(+), 17 deletions(-)

Modified: sandbox/memory/boost/memory.hpp
==============================================================================
--- sandbox/memory/boost/memory.hpp (original)
+++ sandbox/memory/boost/memory.hpp 2008-04-30 14:53:03 EDT (Wed, 30 Apr 2008)
@@ -27,12 +27,12 @@
 #endif
 
 // -------------------------------------------------------------------------
-// class stl_alloc
+// class stl_allocator
 
 NS_BOOST_BEGIN
 
 template <class Type, class AllocT = scoped_alloc>
-class stl_alloc
+class stl_allocator
 {
 private:
         AllocT* m_alloc;
@@ -47,7 +47,7 @@
         typedef Type value_type;
 
     template <class U>
- struct rebind { typedef stl_alloc<U, AllocT> other; };
+ struct rebind { typedef stl_allocator<U, AllocT> other; };
 
 public:
         pointer address(reference val) const
@@ -60,10 +60,10 @@
                   return (0 < count ? count : 1); }
 
 public:
- stl_alloc(AllocT& alloc) : m_alloc(&alloc) {}
+ stl_allocator(AllocT& alloc) : m_alloc(&alloc) {}
 
     template <class U>
- stl_alloc(const stl_alloc<U, AllocT>& rhs) : m_alloc(rhs._Getalloc()) {}
+ stl_allocator(const stl_allocator<U, AllocT>& rhs) : m_alloc(rhs._Getalloc()) {}
 
         pointer allocate(size_type count, const void* = NULL)
                 { return (pointer)m_alloc->allocate(count * sizeof(Type)); }
@@ -81,35 +81,66 @@
         AllocT* _Getalloc() const { return m_alloc; }
 };
 
-template<> class stl_alloc<void, scoped_alloc>
+#if defined(BOOST_MEMORY_SUPPORT_PARTIAL_TEMPLATE)
+
+template <class AllocT>
+class stl_allocator<void, AllocT>
+{
+public:
+ typedef void value_type;
+ typedef void* pointer;
+ typedef const void* const_pointer;
+
+ template <class U>
+ struct rebind { typedef stl_allocator<U, scoped_alloc> other; };
+};
+
+#else
+
+template<> class stl_allocator<void, scoped_alloc>
+{
+public:
+ typedef void value_type;
+ typedef void* pointer;
+ typedef const void* const_pointer;
+
+ template <class U>
+ struct rebind { typedef stl_allocator<U, scoped_alloc> other; };
+};
+
+template<> class stl_allocator<void, auto_alloc>
 {
+public:
     typedef void value_type;
     typedef void* pointer;
     typedef const void* const_pointer;
  
     template <class U>
- struct rebind { typedef stl_alloc<U, scoped_alloc> other; };
+ struct rebind { typedef stl_allocator<U, scoped_alloc> other; };
 };
 
-template<> class stl_alloc<void, auto_alloc>
+template<> class stl_allocator<void, gc_alloc>
 {
+public:
     typedef void value_type;
     typedef void* pointer;
     typedef const void* const_pointer;
  
     template <class U>
- struct rebind { typedef stl_alloc<U, scoped_alloc> other; };
+ struct rebind { typedef stl_allocator<U, scoped_alloc> other; };
 };
 
+#endif
+
 template <class Type, class AllocT>
-inline bool operator==(const stl_alloc<Type, AllocT>&,
- const stl_alloc<Type, AllocT>&) {
+inline bool operator==(const stl_allocator<Type, AllocT>&,
+ const stl_allocator<Type, AllocT>&) {
     return true;
 }
 
 template <class Type, class AllocT>
-inline bool operator!=(const stl_alloc<Type, AllocT>&,
- const stl_alloc<Type, AllocT>&) {
+inline bool operator!=(const stl_allocator<Type, AllocT>&,
+ const stl_allocator<Type, AllocT>&) {
     return false;
 }
 

Modified: sandbox/memory/boost/memory/basic.hpp
==============================================================================
--- sandbox/memory/boost/memory/basic.hpp (original)
+++ sandbox/memory/boost/memory/basic.hpp 2008-04-30 14:53:03 EDT (Wed, 30 Apr 2008)
@@ -47,6 +47,18 @@
 #define NS_BOOST_END }
 #endif
 
+// -------------------------------------------------------------------------
+
+#if defined(_MSC_VER)
+ #if (_MSC_VER > 1200)
+ #define BOOST_MEMORY_SUPPORT_PARTIAL_TEMPLATE
+ #endif
+#else
+ #if defined(__GNUG__)
+ #define BOOST_MEMORY_SUPPORT_PARTIAL_TEMPLATE
+ #endif
+#endif
+
 // =========================================================================
 // BOOST_MEMORY_ASSERT - diagnost
 

Modified: sandbox/memory/libs/memory/test/memory/stl_containers.cpp
==============================================================================
--- sandbox/memory/libs/memory/test/memory/stl_containers.cpp (original)
+++ sandbox/memory/libs/memory/test/memory/stl_containers.cpp 2008-04-30 14:53:03 EDT (Wed, 30 Apr 2008)
@@ -26,7 +26,7 @@
 {
         printf("\n===== Deque (scoped_alloc) =====\n");
         boost::scoped_alloc alloc;
- std::deque<int, boost::stl_alloc<int> > s(alloc);
+ std::deque<int, boost::stl_allocator<int> > s(alloc);
         for (int i = 0; i < Count; ++i)
                 s.push_back(i);
 }
@@ -35,7 +35,7 @@
 {
         printf("\n===== List (scoped_alloc) =====\n");
         boost::scoped_alloc alloc;
- std::list<int, boost::stl_alloc<int> > s(alloc);
+ std::list<int, boost::stl_allocator<int> > s(alloc);
         for (int i = 0; i < Count; ++i)
                 s.push_back(i);
 }
@@ -44,7 +44,7 @@
 {
         printf("\n===== Set (scoped_alloc) =====\n");
         boost::scoped_alloc alloc;
- std::set<int, std::less<int>, boost::stl_alloc<int> > s(std::less<int>(), alloc);
+ std::set<int, std::less<int>, boost::stl_allocator<int> > s(std::less<int>(), alloc);
         for (int i = 0; i < Count; ++i)
                 s.insert(i);
 }
@@ -53,7 +53,7 @@
 {
         printf("\n===== Map (scoped_alloc) =====\n");
         boost::scoped_alloc alloc;
- std::map<int, int, std::less<int>, boost::stl_alloc<int> > s(std::less<int>(), alloc);
+ std::map<int, int, std::less<int>, boost::stl_allocator<int> > s(std::less<int>(), alloc);
         for (int i = 0; i < Count; ++i)
                 s.insert(std::pair<int, int>(i, i));
 }


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