Boost logo

Boost-Commit :

From: daniel_james_at_[hidden]
Date: 2008-04-05 08:52:38


Author: danieljames
Date: 2008-04-05 08:52:38 EDT (Sat, 05 Apr 2008)
New Revision: 44052
URL: http://svn.boost.org/trac/boost/changeset/44052

Log:
Use my allocator implementation so that I can implement some of the new features.
Added:
   branches/unordered/dev/boost/unordered/detail/allocator.hpp (contents, props changed)
Text files modified:
   branches/unordered/dev/boost/unordered_map.hpp | 6 +++---
   branches/unordered/dev/boost/unordered_set.hpp | 6 +++---
   2 files changed, 6 insertions(+), 6 deletions(-)

Added: branches/unordered/dev/boost/unordered/detail/allocator.hpp
==============================================================================
--- (empty file)
+++ branches/unordered/dev/boost/unordered/detail/allocator.hpp 2008-04-05 08:52:38 EDT (Sat, 05 Apr 2008)
@@ -0,0 +1,101 @@
+
+// Copyright 2008 Daniel James.
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_UNORDERED_DETAIL_ALLOCATOR_HPP_INCLUDED
+#define BOOST_UNORDERED_DETAIL_ALLOCATOR_HPP_INCLUDED
+
+namespace boost
+{
+namespace unordered_detail
+{
+ // TODO: Use std::allocator if it's up to the task.
+
+ 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; };
+ };
+
+ template <class T> class allocator {
+ public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef T* pointer;
+ typedef const T* const_pointer;
+ typedef T& reference;
+ typedef const T& const_reference;
+ typedef T value_type;
+
+ template <class U> struct rebind { typedef allocator<U> other; };
+
+ allocator() {}
+ template <class U> allocator(const allocator<U>&) {}
+
+ pointer address(reference x) const { return &x; }
+ const_pointer address(const_reference x) const { return & x; }
+
+ pointer allocate(size_type num, allocator<void>::const_pointer = 0)
+ {
+ return static_cast<pointer>(::operator new(num * sizeof(T)));
+ }
+
+ void deallocate(pointer p, size_type)
+ {
+ ::operator delete(static_cast<void*>(p));
+ }
+
+ size_type max_size() const throw()
+ {
+ return (std::numeric_limits<size_type>::max)();
+ }
+
+ void construct(pointer p, const T& val)
+ {
+ new (static_cast<void*>(p)) T(val);
+ }
+
+#if defined(BOOST_HAS_RVALUE_REFS) && defined(BOOST_HAS_VARIADIC_TMPL)
+ // TODO: I might need my own std::forward. Where will this end?
+ template<class... Args> void construct(pointer p, Args&&... args)
+ {
+ new (static_cast<void*>(p)) T(std::forward<Args>(args)...);
+
+ }
+#else
+ // TODO: Need something smarter...
+ template <class Arg1>
+ void construct(pointer p, Arg1 const& arg1)
+ {
+ new (static_cast<void*>(p)) T(arg1);
+ }
+
+ template <class Arg1, class Arg2>
+ void construct(pointer p, Arg1 const& arg1, Arg2 const& arg2)
+ {
+ new (static_cast<void*>(p)) T(arg1, arg2);
+ }
+
+ template <class Arg1, class Arg2, class Arg3>
+ void construct(pointer p, Arg1 const& arg1, Arg2 const& arg2, Arg3 const& arg3)
+ {
+ new (static_cast<void*>(p)) T(arg1, arg2, arg3);
+ }
+#endif
+
+ void destroy(pointer p)
+ {
+ p->~T();
+ }
+ };
+}
+}
+
+#endif

Modified: branches/unordered/dev/boost/unordered_map.hpp
==============================================================================
--- branches/unordered/dev/boost/unordered_map.hpp (original)
+++ branches/unordered/dev/boost/unordered_map.hpp 2008-04-05 08:52:38 EDT (Sat, 05 Apr 2008)
@@ -16,10 +16,10 @@
 #include <boost/config.hpp>
 
 #include <functional>
-#include <memory>
 
 #include <boost/functional/hash.hpp>
 #include <boost/unordered/detail/hash_table.hpp>
+#include <boost/unordered/detail/allocator.hpp>
 
 namespace boost
 {
@@ -27,7 +27,7 @@
         class T,
         class Hash = hash<Key>,
         class Pred = std::equal_to<Key>,
- class Alloc = std::allocator<std::pair<const Key, T> > >
+ class Alloc = boost::unordered_detail::allocator<std::pair<const Key, T> > >
     class unordered_map
     {
         typedef boost::unordered_detail::hash_types_unique_keys<
@@ -367,7 +367,7 @@
         class T,
         class Hash = hash<Key>,
         class Pred = std::equal_to<Key>,
- class Alloc = std::allocator<std::pair<const Key, T> > >
+ class Alloc = boost::unordered_detail::allocator<std::pair<const Key, T> > >
     class unordered_multimap
     {
         typedef boost::unordered_detail::hash_types_equivalent_keys<

Modified: branches/unordered/dev/boost/unordered_set.hpp
==============================================================================
--- branches/unordered/dev/boost/unordered_set.hpp (original)
+++ branches/unordered/dev/boost/unordered_set.hpp 2008-04-05 08:52:38 EDT (Sat, 05 Apr 2008)
@@ -16,17 +16,17 @@
 #include <boost/config.hpp>
 
 #include <functional>
-#include <memory>
 
 #include <boost/functional/hash.hpp>
 #include <boost/unordered/detail/hash_table.hpp>
+#include <boost/unordered/detail/allocator.hpp>
 
 namespace boost
 {
     template <class Value,
         class Hash = hash<Value>,
         class Pred = std::equal_to<Value>,
- class Alloc = std::allocator<Value> >
+ class Alloc = boost::unordered_detail::allocator<Value> >
     class unordered_set
     {
         typedef boost::unordered_detail::hash_types_unique_keys<
@@ -336,7 +336,7 @@
     template <class Value,
         class Hash = hash<Value>,
         class Pred = std::equal_to<Value>,
- class Alloc = std::allocator<Value> >
+ class Alloc = boost::unordered_detail::allocator<Value> >
     class unordered_multiset
     {
         typedef boost::unordered_detail::hash_types_equivalent_keys<


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