Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54780 - trunk/boost/ptr_container
From: nesotto_at_[hidden]
Date: 2009-07-07 15:21:55


Author: nesotto
Date: 2009-07-07 15:21:53 EDT (Tue, 07 Jul 2009)
New Revision: 54780
URL: http://svn.boost.org/trac/boost/changeset/54780

Log:
initial support for const elements in containers
Text files modified:
   trunk/boost/ptr_container/nullable.hpp | 12 ++++++++++++
   trunk/boost/ptr_container/ptr_array.hpp | 8 +++++---
   trunk/boost/ptr_container/ptr_circular_buffer.hpp | 11 ++++++-----
   trunk/boost/ptr_container/ptr_deque.hpp | 8 ++++----
   trunk/boost/ptr_container/ptr_list.hpp | 17 +++++++++--------
   trunk/boost/ptr_container/ptr_map.hpp | 6 ++++--
   trunk/boost/ptr_container/ptr_map_adapter.hpp | 5 +++++
   trunk/boost/ptr_container/ptr_set.hpp | 9 ++++++---
   trunk/boost/ptr_container/ptr_set_adapter.hpp | 8 ++++++++
   trunk/boost/ptr_container/ptr_unordered_map.hpp | 9 ++++++---
   trunk/boost/ptr_container/ptr_unordered_set.hpp | 14 ++++++++------
   trunk/boost/ptr_container/ptr_vector.hpp | 8 ++++----
   12 files changed, 77 insertions(+), 38 deletions(-)

Modified: trunk/boost/ptr_container/nullable.hpp
==============================================================================
--- trunk/boost/ptr_container/nullable.hpp (original)
+++ trunk/boost/ptr_container/nullable.hpp 2009-07-07 15:21:53 EDT (Tue, 07 Jul 2009)
@@ -18,6 +18,7 @@
 #endif
 
 #include <boost/type_traits/detail/yes_no_type.hpp>
+#include <boost/type_traits/is_const.hpp>
 #include <boost/mpl/eval_if.hpp>
 #include <boost/mpl/identity.hpp>
 #include <boost/config.hpp>
@@ -68,6 +69,17 @@
             type;
     };
 
+ namespace ptr_container_detail
+ {
+ template< class T >
+ struct void_ptr
+ {
+ typedef BOOST_DEDUCED_TYPENAME
+ mpl::if_c< boost::is_const<
+ BOOST_DEDUCED_TYPENAME boost::remove_nullable<T>::type >::value,
+ const void*, void* >::type type;
+ };
+ }
 }
 
 #endif

Modified: trunk/boost/ptr_container/ptr_array.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_array.hpp (original)
+++ trunk/boost/ptr_container/ptr_array.hpp 2009-07-07 15:21:53 EDT (Tue, 07 Jul 2009)
@@ -56,12 +56,14 @@
>
     class ptr_array : public
         ptr_sequence_adapter< T,
- ptr_container_detail::ptr_array_impl<void*,N>,
+ ptr_container_detail::ptr_array_impl<
+ typename ptr_container_detail::void_ptr<T>::type,N>,
                               CloneAllocator >
     {
     private:
         typedef ptr_sequence_adapter< T,
- ptr_container_detail::ptr_array_impl<void*,N>,
+ ptr_container_detail::ptr_array_impl<
+ typename ptr_container_detail::void_ptr<T>::type,N>,
                                       CloneAllocator >
             base_class;
 
@@ -88,7 +90,7 @@
             size_t i = 0;
             for( ; i != N; ++i )
                 this->base()[i] = this->null_policy_allocate_clone(
- static_cast<const T*>( &r[i] ) );
+ static_cast<const U*>( &r[i] ) );
         }
 
         template< class U >

Modified: trunk/boost/ptr_container/ptr_circular_buffer.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_circular_buffer.hpp (original)
+++ trunk/boost/ptr_container/ptr_circular_buffer.hpp 2009-07-07 15:21:53 EDT (Tue, 07 Jul 2009)
@@ -29,16 +29,17 @@
         class Allocator = std::allocator<void*>
>
     class ptr_circular_buffer : public
- ptr_sequence_adapter< T,
- boost::circular_buffer<void*,Allocator>,
+ ptr_sequence_adapter< T, boost::circular_buffer<
+ typename ptr_container_detail::void_ptr<T>::type,Allocator>,
                               CloneAllocator >
     {
- typedef ptr_sequence_adapter< T,
- boost::circular_buffer<void*,Allocator>,
+ typedef ptr_sequence_adapter< T, boost::circular_buffer<
+ typename ptr_container_detail::void_ptr<T>::type,Allocator>,
                                       CloneAllocator >
             base_type;
 
- typedef boost::circular_buffer<void*,Allocator> circular_buffer_type;
+ typedef boost::circular_buffer<typename
+ ptr_container_detail::void_ptr<T>::type,Allocator> circular_buffer_type;
         typedef ptr_circular_buffer<T,CloneAllocator,Allocator> this_type;
         
     public: // typedefs

Modified: trunk/boost/ptr_container/ptr_deque.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_deque.hpp (original)
+++ trunk/boost/ptr_container/ptr_deque.hpp 2009-07-07 15:21:53 EDT (Tue, 07 Jul 2009)
@@ -29,12 +29,12 @@
         class Allocator = std::allocator<void*>
>
     class ptr_deque : public
- ptr_sequence_adapter< T,
- std::deque<void*,Allocator>,
+ ptr_sequence_adapter< T, std::deque<
+ typename ptr_container_detail::void_ptr<T>::type,Allocator>,
                               CloneAllocator >
     {
- typedef ptr_sequence_adapter< T,
- std::deque<void*,Allocator>,
+ typedef ptr_sequence_adapter< T, std::deque<
+ typename ptr_container_detail::void_ptr<T>::type,Allocator>,
                                          CloneAllocator >
           base_class;
 

Modified: trunk/boost/ptr_container/ptr_list.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_list.hpp (original)
+++ trunk/boost/ptr_container/ptr_list.hpp 2009-07-07 15:21:53 EDT (Tue, 07 Jul 2009)
@@ -29,16 +29,17 @@
         class Allocator = std::allocator<void*>
>
     class ptr_list : public
- ptr_sequence_adapter< T,
- std::list<void*,Allocator>,
+ ptr_sequence_adapter< T, std::list<
+ typename ptr_container_detail::void_ptr<T>::type,Allocator>,
                               CloneAllocator >
     {
- typedef ptr_sequence_adapter< T,
- std::list<void*,Allocator>,
+ typedef ptr_sequence_adapter< T, std::list<
+ typename ptr_container_detail::void_ptr<T>::type,Allocator>,
                                          CloneAllocator >
             base_class;
 
         typedef ptr_list<T,CloneAllocator,Allocator> this_type;
+ typedef BOOST_DEDUCED_TYPENAME boost::remove_nullable<T>::type U;
         
     public:
         BOOST_PTR_CONTAINER_DEFINE_SEQEUENCE_MEMBERS( ptr_list,
@@ -52,23 +53,23 @@
         
         void merge( ptr_list& x )
         {
- merge( x, std::less<T>() );
+ merge( x, std::less<U>() );
         }
 
         template< typename Compare >
         void merge( ptr_list& x, Compare comp )
         {
- this->base().merge( x.base(), void_ptr_indirect_fun<Compare,T>( comp ) ); }
+ this->base().merge( x.base(), void_ptr_indirect_fun<Compare,U>( comp ) ); }
 
         void sort()
         {
- sort( std::less<T>() );
+ sort( std::less<U>() );
         };
 
         template< typename Compare >
         void sort( Compare comp )
         {
- this->base().sort( void_ptr_indirect_fun<Compare,T>( comp ) );
+ this->base().sort( void_ptr_indirect_fun<Compare,U>( comp ) );
         }
 
         template< class Pred >

Modified: trunk/boost/ptr_container/ptr_map.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_map.hpp (original)
+++ trunk/boost/ptr_container/ptr_map.hpp 2009-07-07 15:21:53 EDT (Tue, 07 Jul 2009)
@@ -31,10 +31,12 @@
         class Allocator = std::allocator< std::pair<const Key,void*> >
>
     class ptr_map :
- public ptr_map_adapter<T,std::map<Key,void*,
+ public ptr_map_adapter<T,std::map<Key,
+ typename ptr_container_detail::void_ptr<T>::type,
                                Compare,Allocator>,CloneAllocator>
     {
- typedef ptr_map_adapter<T,std::map<Key,void*,
+ typedef ptr_map_adapter<T,std::map<Key,
+ typename ptr_container_detail::void_ptr<T>::type,
                                 Compare,Allocator>,CloneAllocator>
             base_type;
 

Modified: trunk/boost/ptr_container/ptr_map_adapter.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_map_adapter.hpp (original)
+++ trunk/boost/ptr_container/ptr_map_adapter.hpp 2009-07-07 15:21:53 EDT (Tue, 07 Jul 2009)
@@ -442,6 +442,11 @@
                                   const allocator_type& a )
           : base_type( comp, a ) { }
 
+ template< class SizeType >
+ explicit ptr_map_adapter( SizeType n,
+ ptr_container_detail::unordered_associative_container_tag tag )
+ : base_type( n, tag ) { }
+
         template< class Hash, class Pred, class Allocator >
         ptr_map_adapter( const Hash& hash,
                          const Pred& pred,

Modified: trunk/boost/ptr_container/ptr_set.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_set.hpp (original)
+++ trunk/boost/ptr_container/ptr_set.hpp 2009-07-07 15:21:53 EDT (Tue, 07 Jul 2009)
@@ -31,11 +31,14 @@
         class Allocator = std::allocator<void*>
>
     class ptr_set :
- public ptr_set_adapter< Key,
- std::set<void*,void_ptr_indirect_fun<Compare,Key>,Allocator>,
+ public ptr_set_adapter< Key, std::set<
+ typename ptr_container_detail::void_ptr<Key>::type,
+ void_ptr_indirect_fun<Compare,Key>,Allocator>,
                                 CloneAllocator, true >
     {
- typedef ptr_set_adapter< Key, std::set<void*,void_ptr_indirect_fun<Compare,Key>,Allocator>,
+ typedef ptr_set_adapter< Key, std::set<
+ typename ptr_container_detail::void_ptr<Key>::type,
+ void_ptr_indirect_fun<Compare,Key>,Allocator>,
                                  CloneAllocator, true >
              base_type;
 

Modified: trunk/boost/ptr_container/ptr_set_adapter.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_set_adapter.hpp (original)
+++ trunk/boost/ptr_container/ptr_set_adapter.hpp 2009-07-07 15:21:53 EDT (Tue, 07 Jul 2009)
@@ -346,6 +346,14 @@
             BOOST_ASSERT( this->empty() );
         }
 
+ template< class SizeType, class Hash, class Pred, class Allocator >
+ ptr_set_adapter( SizeType n,
+ const Hash& hash,
+ const Pred& pred,
+ const Allocator& a )
+ : base_type( n, hash, pred, a )
+ { }
+
         template< class Hash, class Pred, class Allocator >
         ptr_set_adapter( const Hash& hash,
                          const Pred& pred,

Modified: trunk/boost/ptr_container/ptr_unordered_map.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_unordered_map.hpp (original)
+++ trunk/boost/ptr_container/ptr_unordered_map.hpp 2009-07-07 15:21:53 EDT (Tue, 07 Jul 2009)
@@ -29,13 +29,16 @@
         class Hash = boost::hash<Key>,
         class Pred = std::equal_to<Key>,
         class CloneAllocator = heap_clone_allocator,
- class Allocator = std::allocator< std::pair<const Key,void*> >
+ class Allocator = std::allocator< std::pair<const Key,
+ typename ptr_container_detail::void_ptr<T>::type> >
>
     class ptr_unordered_map :
- public ptr_map_adapter<T,boost::unordered_map<Key,void*,Hash,Pred,Allocator>,
+ public ptr_map_adapter<T,boost::unordered_map<Key,
+ typename ptr_container_detail::void_ptr<T>::type,Hash,Pred,Allocator>,
                                CloneAllocator,false>
     {
- typedef ptr_map_adapter<T,boost::unordered_map<Key,void*,Hash,Pred,Allocator>,
+ typedef ptr_map_adapter<T,boost::unordered_map<Key,
+ typename ptr_container_detail::void_ptr<T>::type,Hash,Pred,Allocator>,
                                CloneAllocator,false>
             base_type;
 

Modified: trunk/boost/ptr_container/ptr_unordered_set.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_unordered_set.hpp (original)
+++ trunk/boost/ptr_container/ptr_unordered_set.hpp 2009-07-07 15:21:53 EDT (Tue, 07 Jul 2009)
@@ -29,16 +29,18 @@
         class Hash = boost::hash<Key>,
         class Pred = std::equal_to<Key>,
         class CloneAllocator = heap_clone_allocator,
- class Allocator = std::allocator<void*>
+ class Allocator = std::allocator< typename ptr_container_detail::void_ptr<Key>::type >
>
     class ptr_unordered_set :
- public ptr_set_adapter< Key,
- boost::unordered_set<void*,void_ptr_indirect_fun<Hash,Key>,
- void_ptr_indirect_fun<Pred,Key>,Allocator>,
+ public ptr_set_adapter< Key, boost::unordered_set<
+ typename ptr_container_detail::void_ptr<Key>::type,
+ void_ptr_indirect_fun<Hash,Key>,
+ void_ptr_indirect_fun<Pred,Key>,Allocator>,
                                 CloneAllocator, false >
     {
- typedef ptr_set_adapter< Key,
- boost::unordered_set<void*,void_ptr_indirect_fun<Hash,Key>,
+ typedef ptr_set_adapter< Key, boost::unordered_set<
+ typename ptr_container_detail::void_ptr<Key>::type,
+ void_ptr_indirect_fun<Hash,Key>,
                                  void_ptr_indirect_fun<Pred,Key>,Allocator>,
                                  CloneAllocator, false >
              base_type;

Modified: trunk/boost/ptr_container/ptr_vector.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_vector.hpp (original)
+++ trunk/boost/ptr_container/ptr_vector.hpp 2009-07-07 15:21:53 EDT (Tue, 07 Jul 2009)
@@ -29,12 +29,12 @@
         class Allocator = std::allocator<void*>
>
     class ptr_vector : public
- ptr_sequence_adapter< T,
- std::vector<void*,Allocator>,
+ ptr_sequence_adapter< T, std::vector<
+ typename ptr_container_detail::void_ptr<T>::type,Allocator>,
                               CloneAllocator >
     {
- typedef ptr_sequence_adapter< T,
- std::vector<void*,Allocator>,
+ typedef ptr_sequence_adapter< T, std::vector<
+ typename ptr_container_detail::void_ptr<T>::type,Allocator>,
                                       CloneAllocator >
             base_class;
 


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