mirror of
				https://github.com/boostorg/unordered.git
				synced 2025-10-31 15:51:36 +01:00 
			
		
		
		
	Fixed support for allocators with explicit copy constructors (#234)
				
					
				
			* added tests for explicit allocators * made explicit_alloc_ctor_tests work by adhering to the principle that classes templated with Allocator should accept exactly Allocator objects * removed TMP machinery older compilers choke about * initialized variables * updated release notes * fixed PR number
This commit is contained in:
		| @@ -1,4 +1,4 @@ | ||||
| // Copyright (C) 2022-2023 Joaquin M Lopez Munoz. | ||||
| // Copyright (C) 2022-2024 Joaquin M Lopez Munoz. | ||||
| // Copyright (C) 2022 Christian Mazakas | ||||
| // | ||||
| // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||||
| @@ -518,7 +518,8 @@ namespace boost { | ||||
|         } | ||||
|  | ||||
|         grouped_bucket_array(size_type n, const Allocator& al) | ||||
|             : empty_value<node_allocator_type>(empty_init_t(), al), | ||||
|             : empty_value<node_allocator_type>( | ||||
|                 empty_init_t(), node_allocator_type(al)), | ||||
|               size_index_(0), size_(0), buckets(), groups() | ||||
|         { | ||||
|           if (n == 0) { | ||||
| @@ -678,12 +679,17 @@ namespace boost { | ||||
|  | ||||
|         bucket_allocator_type get_bucket_allocator() const | ||||
|         { | ||||
|           return this->get_node_allocator(); | ||||
|           return bucket_allocator_type(this->get_node_allocator()); | ||||
|         } | ||||
|  | ||||
|         group_allocator_type get_group_allocator() const | ||||
|         { | ||||
|           return this->get_node_allocator(); | ||||
|           return group_allocator_type(this->get_node_allocator()); | ||||
|         } | ||||
|  | ||||
|         Allocator get_allocator() const | ||||
|         { | ||||
|           return Allocator(this->get_node_allocator()); | ||||
|         } | ||||
|  | ||||
|         size_type buckets_len() const noexcept { return size_ + 1; } | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| /* Fast open-addressing concurrent hash table. | ||||
|  * | ||||
|  * Copyright 2023 Joaquin M Lopez Munoz. | ||||
|  * Copyright 2023-2024 Joaquin M Lopez Munoz. | ||||
|  * Copyright 2024 Braden Ganetsky. | ||||
|  * Distributed under the Boost Software License, Version 1.0. | ||||
|  * (See accompanying file LICENSE_1_0.txt or copy at | ||||
| @@ -259,6 +259,7 @@ struct concurrent_table_arrays:table_arrays<Value,Group,SizePolicy,Allocator> | ||||
|     typename boost::allocator_pointer<group_access_allocator_type>::type; | ||||
|  | ||||
|   using super=table_arrays<Value,Group,SizePolicy,Allocator>; | ||||
|   using allocator_type=typename super::allocator_type; | ||||
|  | ||||
|   concurrent_table_arrays(const super& arrays,group_access_pointer pga): | ||||
|     super{arrays},group_accesses_{pga}{} | ||||
| @@ -267,12 +268,11 @@ struct concurrent_table_arrays:table_arrays<Value,Group,SizePolicy,Allocator> | ||||
|     return boost::to_address(group_accesses_); | ||||
|   } | ||||
|  | ||||
|   static concurrent_table_arrays new_( | ||||
|     group_access_allocator_type al,std::size_t n) | ||||
|   static concurrent_table_arrays new_(allocator_type al,std::size_t n) | ||||
|   { | ||||
|     super x{super::new_(al,n)}; | ||||
|     BOOST_TRY{ | ||||
|       return new_group_access(al,x); | ||||
|       return new_group_access(group_access_allocator_type(al),x); | ||||
|     } | ||||
|     BOOST_CATCH(...){ | ||||
|       super::delete_(al,x); | ||||
| @@ -322,10 +322,9 @@ struct concurrent_table_arrays:table_arrays<Value,Group,SizePolicy,Allocator> | ||||
|     return arrays; | ||||
|   } | ||||
|  | ||||
|   static void delete_( | ||||
|     group_access_allocator_type al,concurrent_table_arrays& arrays)noexcept | ||||
|   static void delete_(allocator_type al,concurrent_table_arrays& arrays)noexcept | ||||
|   { | ||||
|     delete_group_access(al,arrays); | ||||
|     delete_group_access(group_access_allocator_type(al),arrays); | ||||
|     super::delete_(al,arrays); | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| /* Common base for Boost.Unordered open-addressing tables. | ||||
|  * | ||||
|  * Copyright 2022-2023 Joaquin M Lopez Munoz. | ||||
|  * Copyright 2022-2024 Joaquin M Lopez Munoz. | ||||
|  * Copyright 2023 Christian Mazakas. | ||||
|  * Copyright 2024 Braden Ganetsky. | ||||
|  * Distributed under the Boost Software License, Version 1.0. | ||||
| @@ -977,7 +977,12 @@ struct arrays_holder | ||||
|   arrays_holder(arrays_holder const&); | ||||
|   arrays_holder& operator=(arrays_holder const&)=delete; | ||||
|  | ||||
|   ~arrays_holder(){if(!released_)arrays_.delete_(al_,arrays_);} | ||||
|   ~arrays_holder() | ||||
|   { | ||||
|     if(!released_){ | ||||
|       arrays_.delete_(typename Arrays::allocator_type(al_),arrays_); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   const Arrays& release() | ||||
|   { | ||||
| @@ -1974,7 +1979,7 @@ private: | ||||
|  | ||||
|   arrays_type new_arrays(std::size_t n)const | ||||
|   { | ||||
|     return arrays_type::new_(al(),n); | ||||
|     return arrays_type::new_(typename arrays_type::allocator_type(al()),n); | ||||
|   } | ||||
|  | ||||
|   arrays_type new_arrays_for_growth()const | ||||
| @@ -1995,7 +2000,7 @@ private: | ||||
|  | ||||
|   void delete_arrays(arrays_type& arrays_)noexcept | ||||
|   { | ||||
|     arrays_type::delete_(al(),arrays_); | ||||
|     arrays_type::delete_(typename arrays_type::allocator_type(al()),arrays_); | ||||
|   } | ||||
|  | ||||
|   arrays_holder_type make_arrays(std::size_t n)const | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| // Copyright (C) 2003-2004 Jeremy B. Maitin-Shepard. | ||||
| // Copyright (C) 2005-2016 Daniel James | ||||
| // Copyright (C) 2022-2023 Joaquin M Lopez Munoz. | ||||
| // Copyright (C) 2022-2024 Joaquin M Lopez Munoz. | ||||
| // Copyright (C) 2022-2023 Christian Mazakas | ||||
| // Copyright (C) 2024 Braden Ganetsky | ||||
| // | ||||
| @@ -1366,14 +1366,14 @@ namespace boost { | ||||
|         } | ||||
|  | ||||
|         table(std::size_t num_buckets, hasher const& hf, key_equal const& eq, | ||||
|           node_allocator_type const& a) | ||||
|           value_allocator const& a) | ||||
|             : functions(hf, eq), size_(0), mlf_(1.0f), max_load_(0), | ||||
|               buckets_(num_buckets, a) | ||||
|         { | ||||
|           recalculate_max_load(); | ||||
|         } | ||||
|  | ||||
|         table(table const& x, node_allocator_type const& a) | ||||
|         table(table const& x, value_allocator const& a) | ||||
|             : functions(x), size_(0), mlf_(x.mlf_), max_load_(0), | ||||
|               buckets_(x.size_, a) | ||||
|         { | ||||
| @@ -1388,7 +1388,7 @@ namespace boost { | ||||
|           x.max_load_ = 0; | ||||
|         } | ||||
|  | ||||
|         table(table& x, node_allocator_type const& a, | ||||
|         table(table& x, value_allocator const& a, | ||||
|           boost::unordered::detail::move_tag m) | ||||
|             : functions(x, m), size_(0), mlf_(x.mlf_), max_load_(0), | ||||
|               buckets_(x.bucket_count(), a) | ||||
| @@ -2722,7 +2722,7 @@ namespace boost { | ||||
|       inline void table<Types>::rehash_impl(std::size_t num_buckets) | ||||
|       { | ||||
|         bucket_array_type new_buckets( | ||||
|           num_buckets, buckets_.get_node_allocator()); | ||||
|           num_buckets, buckets_.get_allocator()); | ||||
|  | ||||
|         BOOST_TRY | ||||
|         { | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| // Copyright (C) 2003-2004 Jeremy B. Maitin-Shepard. | ||||
| // Copyright (C) 2005-2011 Daniel James. | ||||
| // Copyright (C) 2022-2023 Christian Mazakas | ||||
| // Copyright (C) 2024 Joaquin M Lopez Munoz. | ||||
| // 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) | ||||
|  | ||||
| @@ -158,7 +159,7 @@ namespace boost { | ||||
|  | ||||
|       allocator_type get_allocator() const noexcept | ||||
|       { | ||||
|         return table_.node_alloc(); | ||||
|         return allocator_type(table_.node_alloc()); | ||||
|       } | ||||
|  | ||||
|       //       // iterators | ||||
| @@ -254,12 +255,15 @@ namespace boost { | ||||
|       node_type extract(const_iterator position) | ||||
|       { | ||||
|         return node_type( | ||||
|           table_.extract_by_iterator_unique(position), table_.node_alloc()); | ||||
|           table_.extract_by_iterator_unique(position), | ||||
|           allocator_type(table_.node_alloc())); | ||||
|       } | ||||
|  | ||||
|       node_type extract(const key_type& k) | ||||
|       { | ||||
|         return node_type(table_.extract_by_key_impl(k), table_.node_alloc()); | ||||
|         return node_type( | ||||
|           table_.extract_by_key_impl(k), | ||||
|           allocator_type(table_.node_alloc())); | ||||
|       } | ||||
|  | ||||
|       template <class Key> | ||||
| @@ -268,8 +272,9 @@ namespace boost { | ||||
|         node_type>::type | ||||
|       extract(Key&& k) | ||||
|       { | ||||
|         return node_type(table_.extract_by_key_impl(std::forward<Key>(k)), | ||||
|           table_.node_alloc()); | ||||
|         return node_type( | ||||
|           table_.extract_by_key_impl(std::forward<Key>(k)), | ||||
|           allocator_type(table_.node_alloc())); | ||||
|       } | ||||
|  | ||||
|       insert_return_type insert(node_type&& np) | ||||
| @@ -806,7 +811,7 @@ namespace boost { | ||||
|  | ||||
|       allocator_type get_allocator() const noexcept | ||||
|       { | ||||
|         return table_.node_alloc(); | ||||
|         return allocator_type(table_.node_alloc()); | ||||
|       } | ||||
|  | ||||
|       // iterators | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| // Copyright (C) 2003-2004 Jeremy B. Maitin-Shepard. | ||||
| // Copyright (C) 2005-2011 Daniel James. | ||||
| // Copyright (C) 2022-2023 Christian Mazakas | ||||
| // Copyright (C) 2024 Joaquin M Lopez Munoz. | ||||
| // 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) | ||||
|  | ||||
| @@ -154,7 +155,7 @@ namespace boost { | ||||
|  | ||||
|       allocator_type get_allocator() const noexcept | ||||
|       { | ||||
|         return table_.node_alloc(); | ||||
|         return allocator_type(table_.node_alloc()); | ||||
|       } | ||||
|  | ||||
|       // iterators | ||||
| @@ -252,12 +253,15 @@ namespace boost { | ||||
|       node_type extract(const_iterator position) | ||||
|       { | ||||
|         return node_type( | ||||
|           table_.extract_by_iterator_unique(position), table_.node_alloc()); | ||||
|           table_.extract_by_iterator_unique(position), | ||||
|           allocator_type(table_.node_alloc())); | ||||
|       } | ||||
|  | ||||
|       node_type extract(const key_type& k) | ||||
|       { | ||||
|         return node_type(table_.extract_by_key_impl(k), table_.node_alloc()); | ||||
|         return node_type( | ||||
|           table_.extract_by_key_impl(k), | ||||
|           allocator_type(table_.node_alloc())); | ||||
|       } | ||||
|  | ||||
|       template <class Key> | ||||
| @@ -266,7 +270,9 @@ namespace boost { | ||||
|         node_type>::type | ||||
|       extract(const Key& k) | ||||
|       { | ||||
|         return node_type(table_.extract_by_key_impl(k), table_.node_alloc()); | ||||
|         return node_type( | ||||
|           table_.extract_by_key_impl(k), | ||||
|           allocator_type(table_.node_alloc())); | ||||
|       } | ||||
|  | ||||
|       insert_return_type insert(node_type&& np) | ||||
| @@ -647,7 +653,7 @@ namespace boost { | ||||
|  | ||||
|       allocator_type get_allocator() const noexcept | ||||
|       { | ||||
|         return table_.node_alloc(); | ||||
|         return allocator_type(table_.node_alloc()); | ||||
|       } | ||||
|  | ||||
|       // iterators | ||||
|   | ||||
		Reference in New Issue
	
	Block a user