Compare commits

..

4 Commits

Author SHA1 Message Date
joaquintides d689613172 protected visitation against spurious insertion sentinels 2023-12-27 12:32:31 +01:00
joaquintides 8365ccb78a fixed is_reserved 2023-12-26 18:11:22 +01:00
joaquintides 0a6da6979f protected for_all_elements(_while) against transient slot reserves 2023-12-26 09:53:29 +01:00
joaquintides 31c33faf57 added almost-latch-free insertion for regular-layout group_type 2023-12-25 20:25:34 +01:00
35 changed files with 282 additions and 1359 deletions
+5 -23
View File
@@ -102,16 +102,16 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
[
linux_pipeline(
"Linux 14.04 GCC 4.8* 32/64",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-4.8', CXXSTD: '11', ADDRMD: '32,64' },
"g++-4.8-multilib",
"cppalliance/droneubuntu1404:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11', ADDRMD: '32,64' },
),
linux_pipeline(
"Linux 14.04 GCC 4.9 32/64",
"cppalliance/droneubuntu1604:1",
"cppalliance/droneubuntu1404:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-4.9', CXXSTD: '11', ADDRMD: '32,64' },
"g++-4.9-multilib",
[ "ppa:ubuntu-toolchain-r/test" ],
),
linux_pipeline(
@@ -468,7 +468,7 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
windows_pipeline(
"Windows VS2015 msvc-14.0",
"cppalliance/dronevs2015",
{ TOOLSET: 'msvc-14.0', CXXSTD: '14,latest', 'B2_DONT_EMBED_MANIFEST': 1 },
{ TOOLSET: 'msvc-14.0', CXXSTD: '14,latest' },
),
windows_pipeline(
@@ -477,33 +477,15 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
{ TOOLSET: 'msvc-14.1', CXXSTD: '14,17,latest' },
),
windows_pipeline(
"Windows VS2017 msvc-14.1 permissive-",
"cppalliance/dronevs2017",
{ TOOLSET: 'msvc-14.1', CXXSTD: '14,17', CXXFLAGS: '/permissive-' },
),
windows_pipeline(
"Windows VS2019 msvc-14.2",
"cppalliance/dronevs2019",
{ TOOLSET: 'msvc-14.2', CXXSTD: '14,17,20,latest' },
),
windows_pipeline(
"Windows VS2019 msvc-14.2 permissive-",
"cppalliance/dronevs2019",
{ TOOLSET: 'msvc-14.2', CXXSTD: '14,17', CXXFLAGS: '/permissive-' },
),
windows_pipeline(
"Windows VS2022 msvc-14.3",
"cppalliance/dronevs2022:1",
{ TOOLSET: 'msvc-14.3', CXXSTD: '14,17,20,latest' },
),
windows_pipeline(
"Windows VS2022 msvc-14.3 permissive-",
"cppalliance/dronevs2022:1",
{ TOOLSET: 'msvc-14.3', CXXSTD: '14,17', CXXFLAGS: '/permissive-' },
),
]
+1 -2
View File
@@ -20,5 +20,4 @@ b2 -d0 headers
if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
if not "%CXXFLAGS%" == "" set CXXFLAGS=cxxflags=%CXXFLAGS%
b2 --abbreviate-paths -j3 libs/%LIBRARY%/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% %CXXFLAGS% variant=debug,release embed-manifest-via=linker
b2 --abbreviate-paths -j3 libs/%LIBRARY%/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release embed-manifest-via=linker
-1
View File
@@ -265,7 +265,6 @@ jobs:
- { toolset: msvc-14.3, cxxstd: '14,17,20,latest', addrmd: '32,64', os: 'windows-2022', variant: 'debug,release' }
- { toolset: msvc-14.3, cxxstd: '14', addrmd: '64', os: 'windows-2022', variant: 'debug', defines: '_ALLOW_RTCc_IN_STL', cxxflags: '/RTCc' }
- { toolset: msvc-14.3, cxxstd: '14', addrmd: '32', os: 'windows-2022', variant: 'debug', defines: '_ALLOW_RTCc_IN_STL', cxxflags: '"/RTCc /arch:IA32"' }
- { toolset: msvc-14.3, cxxstd: '14,17', addrmd: '32,64', os: 'windows-2022', variant: 'debug,release', cxxflags: '/permissive-' }
- { toolset: clang-win, cxxstd: '14,17,latest', addrmd: '32,64', os: 'windows-2022', variant: 'debug,release' }
- { toolset: gcc, cxxstd: '11,14,17,2a', addrmd: '64', os: 'windows-2019', variant: 'debug,release' }
-7
View File
@@ -6,13 +6,6 @@
:github-pr-url: https://github.com/boostorg/unordered/pull
:cpp: C++
== Release 1.85.0
* Optimized `emplace()` for a `value_type` or `init_type` (if applicable) argument to bypass creating an intermediate object. The argument is already the same type as the would-be intermediate object.
* Optimized `emplace()` for `k,v` arguments on map containers to delay constructing the object until it is certain that an element should be inserted. This optimization happens when the map's `key_type` is move constructible or when the `k` argument is a `key_type`.
* Fixed support for allocators with `explicit` copy constructors ({github-pr-url}/234[PR#234^]).
* Fixed bug in the `const` version of `unordered_multimap::find(k, hash, eq)` ({github-pr-url}/238[PR#238^]).
== Release 1.84.0 - Major update
* Added `boost::concurrent_flat_set`.
+1 -3
View File
@@ -908,9 +908,7 @@ Inserts an object, constructed with the arguments `args`, in the table if and on
Requires:;; `value_type` is constructible from `args`.
Returns:;; `true` if an insert took place.
Concurrency:;; Blocking on rehashing of `*this`.
Notes:;; Invalidates pointers and references to elements if a rehashing is issued. +
+
If `args...` is of the form `k,v`, it delays constructing the whole object until it is certain that an element should be inserted, using only the `k` argument to check.
Notes:;; Invalidates pointers and references to elements if a rehashing is issued.
---
+1 -3
View File
@@ -11,10 +11,8 @@ Copyright (C) 2005-2008 Daniel James
Copyright (C) 2022-2023 Christian Mazakas
Copyright (C) 2022-2024 Joaquín M López Muñoz
Copyright (C) 2022-2023 Joaquín M López Muñoz
Copyright (C) 2022-2023 Peter Dimov
Copyright (C) 2024 Braden Ganetsky
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)
-4
View File
@@ -750,8 +750,6 @@ Returns:;; The `bool` component of the return type is `true` if an insert took p
If an insert took place, then the iterator points to the newly inserted element. Otherwise, it points to the element with equivalent key.
Throws:;; If an exception is thrown by an operation other than a call to `hasher` the function has no effect.
Notes:;; Can invalidate iterators, pointers and references, but only if the insert causes the load to be greater than the maximum load. +
+
If `args...` is of the form `k,v`, it delays constructing the whole object until it is certain that an element should be inserted, using only the `k` argument to check.
---
@@ -771,8 +769,6 @@ Returns:;; The `bool` component of the return type is `true` if an insert took p
If an insert took place, then the iterator points to the newly inserted element. Otherwise, it points to the element with equivalent key.
Throws:;; If an exception is thrown by an operation other than a call to `hasher` the function has no effect.
Notes:;; Can invalidate iterators, pointers and references, but only if the insert causes the load to be greater than the maximum load. +
+
If `args...` is of the form `k,v`, it delays constructing the whole object until it is certain that an element should be inserted, using only the `k` argument to check.
---
+2 -6
View File
@@ -797,9 +797,7 @@ If an insert took place, then the iterator points to the newly inserted element.
Throws:;; If an exception is thrown by an operation other than a call to `hasher` the function has no effect.
Notes:;; Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor. +
+
Pointers and references to elements are never invalidated. +
+
If `args...` is of the form `k,v`, it delays constructing the whole object until it is certain that an element should be inserted, using only the `k` argument to check. This optimization happens when the map's `key_type` is move constructible or when the `k` argument is a `key_type`.
Pointers and references to elements are never invalidated.
---
@@ -820,9 +818,7 @@ Notes:;; The standard is fairly vague on the meaning of the hint. But the only p
+
Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor. +
+
Pointers and references to elements are never invalidated. +
+
If `args...` is of the form `k,v`, it delays constructing the whole object until it is certain that an element should be inserted, using only the `k` argument to check. This optimization happens when the map's `key_type` is move constructible or when the `k` argument is a `key_type`.
Pointers and references to elements are never invalidated.
---
-4
View File
@@ -767,8 +767,6 @@ Returns:;; The `bool` component of the return type is `true` if an insert took p
If an insert took place, then the iterator points to the newly inserted element. Otherwise, it points to the element with equivalent key.
Throws:;; If an exception is thrown by an operation other than a call to `hasher` the function has no effect.
Notes:;; Can invalidate iterators, but only if the insert causes the load to be greater than the maximum load. +
+
If `args...` is of the form `k,v`, it delays constructing the whole object until it is certain that an element should be inserted, using only the `k` argument to check. This optimization happens when `key_type` is move constructible or when the `k` argument is a `key_type`.
---
@@ -788,8 +786,6 @@ Returns:;; The `bool` component of the return type is `true` if an insert took p
If an insert took place, then the iterator points to the newly inserted element. Otherwise, it points to the element with equivalent key.
Throws:;; If an exception is thrown by an operation other than a call to `hasher` the function has no effect.
Notes:;; Can invalidate iterators, but only if the insert causes the load to be greater than the maximum load. +
+
If `args...` is of the form `k,v`, it delays constructing the whole object until it is certain that an element should be inserted, using only the `k` argument to check. This optimization happens when `key_type` is move constructible or when the `k` argument is a `key_type`.
---
@@ -1,59 +0,0 @@
/* Copyright 2024 Braden Ganetsky.
* 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)
*
* See https://www.boost.org/libs/unordered for library home page.
*/
#ifndef BOOST_UNORDERED_DETAIL_ALLOCATOR_CONSTRUCTED_HPP
#define BOOST_UNORDERED_DETAIL_ALLOCATOR_CONSTRUCTED_HPP
#include <boost/core/allocator_traits.hpp>
#include <boost/unordered/detail/opt_storage.hpp>
namespace boost {
namespace unordered {
namespace detail {
struct allocator_policy
{
template <class Allocator, class T, class... Args>
static void construct(Allocator& a, T* p, Args&&... args)
{
boost::allocator_construct(a, p, std::forward<Args>(args)...);
}
template <class Allocator, class T>
static void destroy(Allocator& a, T* p)
{
boost::allocator_destroy(a, p);
}
};
/* constructs a stack-based object with the given policy and allocator */
template <class Allocator, class T, class Policy = allocator_policy>
class allocator_constructed
{
opt_storage<T> storage;
Allocator alloc;
public:
template <class... Args>
allocator_constructed(Allocator const& alloc_, Args&&... args)
: alloc(alloc_)
{
Policy::construct(
alloc, storage.address(), std::forward<Args>(args)...);
}
~allocator_constructed() { Policy::destroy(alloc, storage.address()); }
T& value() { return *storage.address(); }
};
} /* namespace detail */
} /* namespace unordered */
} /* namespace boost */
#endif
+4 -10
View File
@@ -1,4 +1,4 @@
// Copyright (C) 2022-2024 Joaquin M Lopez Munoz.
// Copyright (C) 2022-2023 Joaquin M Lopez Munoz.
// Copyright (C) 2022 Christian Mazakas
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -518,8 +518,7 @@ namespace boost {
}
grouped_bucket_array(size_type n, const Allocator& al)
: empty_value<node_allocator_type>(
empty_init_t(), node_allocator_type(al)),
: empty_value<node_allocator_type>(empty_init_t(), al),
size_index_(0), size_(0), buckets(), groups()
{
if (n == 0) {
@@ -679,17 +678,12 @@ namespace boost {
bucket_allocator_type get_bucket_allocator() const
{
return bucket_allocator_type(this->get_node_allocator());
return this->get_node_allocator();
}
group_allocator_type get_group_allocator() const
{
return group_allocator_type(this->get_node_allocator());
}
Allocator get_allocator() const
{
return Allocator(this->get_node_allocator());
return this->get_node_allocator();
}
size_type buckets_len() const noexcept { return size_ + 1; }
@@ -1,7 +1,6 @@
/* Fast open-addressing concurrent hash table.
*
* Copyright 2023-2024 Joaquin M Lopez Munoz.
* Copyright 2024 Braden Ganetsky.
* Copyright 2023 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)
@@ -29,7 +28,6 @@
#include <boost/unordered/detail/foa/tuple_rotate_right.hpp>
#include <boost/unordered/detail/serialization_version.hpp>
#include <boost/unordered/detail/static_assert.hpp>
#include <boost/unordered/detail/type_traits.hpp>
#include <cstddef>
#include <functional>
#include <initializer_list>
@@ -200,13 +198,13 @@ private:
template<typename Integral>
struct atomic_integral
{
operator Integral()const{return n.load(std::memory_order_relaxed);}
void operator=(Integral m){n.store(m,std::memory_order_relaxed);}
void operator|=(Integral m){n.fetch_or(m,std::memory_order_relaxed);}
void operator&=(Integral m){n.fetch_and(m,std::memory_order_relaxed);}
operator Integral()const{return n.load(std::memory_order_acquire);}
void operator=(Integral m){n.store(m,std::memory_order_release);}
void operator|=(Integral m){n.fetch_or(m);}
void operator&=(Integral m){n.fetch_and(m);}
atomic_integral& operator=(atomic_integral const& rhs) {
n.store(rhs.n.load(std::memory_order_relaxed),std::memory_order_relaxed);
n.store(rhs.n.load());
return *this;
}
@@ -259,7 +257,6 @@ 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}{}
@@ -268,11 +265,12 @@ struct concurrent_table_arrays:table_arrays<Value,Group,SizePolicy,Allocator>
return boost::to_address(group_accesses_);
}
static concurrent_table_arrays new_(allocator_type al,std::size_t n)
static concurrent_table_arrays new_(
group_access_allocator_type al,std::size_t n)
{
super x{super::new_(al,n)};
BOOST_TRY{
return new_group_access(group_access_allocator_type(al),x);
return new_group_access(al,x);
}
BOOST_CATCH(...){
super::delete_(al,x);
@@ -322,9 +320,10 @@ struct concurrent_table_arrays:table_arrays<Value,Group,SizePolicy,Allocator>
return arrays;
}
static void delete_(allocator_type al,concurrent_table_arrays& arrays)noexcept
static void delete_(
group_access_allocator_type al,concurrent_table_arrays& arrays)noexcept
{
delete_group_access(group_access_allocator_type(al),arrays);
delete_group_access(al,arrays);
super::delete_(al,arrays);
}
@@ -683,26 +682,6 @@ public:
return construct_and_emplace(std::forward<Args>(args)...);
}
/* Optimization for value_type and init_type, to avoid constructing twice */
template<typename Value>
BOOST_FORCEINLINE auto emplace(Value&& x)->typename std::enable_if<
detail::is_similar_to_any<Value,value_type,init_type>::value,bool>::type
{
return emplace_impl(std::forward<Value>(x));
}
/* Optimizations for maps for (k,v) to avoid eagerly constructing value */
template <typename K, typename V>
BOOST_FORCEINLINE auto emplace(K&& k, V&& v) ->
typename std::enable_if<is_emplace_kv_able<concurrent_table, K>::value,
bool>::type
{
alloc_cted_or_fwded_key_type<type_policy, Allocator, K&&> x(
this->al(), std::forward<K>(k));
return emplace_impl(
try_emplace_args_t{}, x.move_or_fwd(), std::forward<V>(v));
}
BOOST_FORCEINLINE bool
insert(const init_type& x){return emplace_impl(x);}
@@ -1198,7 +1177,7 @@ private:
do{
auto n=unchecked_countr_zero(mask);
if(BOOST_LIKELY(
pg->is_occupied(n)&&bool(this->pred()(x,this->key_from(p[n]))))){
is_occupied(pg,n)&&bool(this->pred()(x,this->key_from(p[n]))))){
f(pg,n,p+n);
return 1;
}
@@ -1257,7 +1236,7 @@ private:
do{
auto n=unchecked_countr_zero(mask);
if(BOOST_LIKELY(
pg->is_occupied(n)&&
is_occupied(pg,n)&&
bool(this->pred()(*it,this->key_from(p[n]))))){
f(cast_for(access_mode,type_policy::value_from(p[n])));
++res;
@@ -1332,7 +1311,7 @@ private:
{
auto lck=shared_access();
alloc_cted_insert_type<type_policy,Allocator,Args...> x(
auto x=alloc_make_insert_type<type_policy>(
this->al(),std::forward<Args>(args)...);
int res=unprotected_norehash_emplace_or_visit(
access_mode,std::forward<F>(f),type_policy::move(x.value()));
@@ -1457,10 +1436,103 @@ private:
bool commit_=false;
};
struct latch_free_reserve_slot
{
latch_free_reserve_slot(group_type* pg_,std::size_t pos_):pg{pg_},pos{pos_}
{
unsigned char expected=0;
succeeded_=reinterpret_cast<std::atomic<unsigned char>*>(pg)[pos].
compare_exchange_weak(expected,1);
}
~latch_free_reserve_slot()
{
if(succeeded_&&!commit_)pg->reset(pos);
}
bool succeeded()const{return succeeded_;}
void commit(){commit_=true;}
group_type *pg;
std::size_t pos;
bool succeeded_;
bool commit_=false;
};
struct assign_insert_counter_on_exit
{
~assign_insert_counter_on_exit(){counter=x;}
group_insert_counter_type &counter;
boost::uint32_t x;
};
template<typename GroupAccessMode,typename F,typename... Args>
BOOST_FORCEINLINE int
unprotected_norehash_emplace_or_visit(
GroupAccessMode access_mode,F&& f,Args&&... args)
{
return unprotected_norehash_emplace_or_visit_with_layout(
std::integral_constant<bool,group_type::regular_layout>{},
access_mode,std::forward<F>(f),std::forward<Args>(args)...);
}
template<typename GroupAccessMode,typename F,typename... Args>
BOOST_FORCEINLINE int
unprotected_norehash_emplace_or_visit_with_layout(
std::true_type, /* regular layout, almost-latch-free */
GroupAccessMode access_mode,F&& f,Args&&... args)
{
const auto &k=this->key_from(std::forward<Args>(args)...);
auto hash=this->hash_for(k);
auto pos0=this->position_for(hash);
for(;;){
startover:
boost::uint32_t counter=0;
while(BOOST_UNLIKELY((counter=insert_counter(pos0))%2==1)){}
if(unprotected_visit(
access_mode,k,pos0,hash,std::forward<F>(f)))return 0;
reserve_size rsize(*this);
if(BOOST_LIKELY(rsize.succeeded())){
for(prober pb(pos0);;pb.next(this->arrays.groups_size_mask)){
auto pos=pb.get();
auto pg=this->arrays.groups()+pos;
auto mask=pg->match_available();
if(BOOST_LIKELY(mask!=0)){
auto n=unchecked_countr_zero(mask);
latch_free_reserve_slot rslot{pg,n};
if(BOOST_UNLIKELY(!rslot.succeeded())){
/* slot wasn't empty */
goto startover;
}
if(BOOST_UNLIKELY(
!insert_counter(pos0).compare_exchange_weak(counter,counter+1))){
/* other thread inserted from pos0, need to start over */
goto startover;
}
assign_insert_counter_on_exit a{insert_counter(pos0),counter+2};
auto p=this->arrays.elements()+pos*N+n;
this->construct_element(p,std::forward<Args>(args)...);
pg->set(n,hash);
rslot.commit();
rsize.commit();
return 1;
}
pg->mark_overflow(hash);
}
}
else return -1;
}
}
template<typename GroupAccessMode,typename F,typename... Args>
BOOST_FORCEINLINE int
unprotected_norehash_emplace_or_visit_with_layout(
std::false_type, /* non-regular layout, latched */
GroupAccessMode access_mode,F&& f,Args&&... args)
{
const auto &k=this->key_from(std::forward<Args>(args)...);
auto hash=this->hash_for(k);
@@ -1507,6 +1579,46 @@ private:
}
}
/* check occupation with previous unsynced match */
static bool is_occupied(group_type* pg,std::size_t pos)
{
return is_occupied(
std::integral_constant<bool,group_type::regular_layout>{},pg,pos);
}
static bool is_occupied(std::true_type,group_type* pg,std::size_t pos)
{
/* regular layout, almost-latch-free insertion -> possible reserved slot */
return reinterpret_cast<std::atomic<unsigned char>*>(pg)[pos]>1;
}
static bool is_occupied(std::false_type,group_type* pg,std::size_t pos)
{
/* non-regular layout, latched insertion -> no reserved slots */
return pg->is_occupied(pos);
}
/* check occupation with previous synced match */
static bool is_really_occupied(group_type* pg,std::size_t pos)
{
return is_really_occupied(
std::integral_constant<bool,group_type::regular_layout>{},pg,pos);
}
static bool is_really_occupied(std::true_type,group_type* pg,std::size_t pos)
{
/* regular layout, almost-latch-free insertion -> possible reserved slot */
return reinterpret_cast<std::atomic<unsigned char>*>(pg)[pos]>1;
}
static bool is_really_occupied(std::false_type,group_type*,std::size_t)
{
/* non-regular layout, latched insertion -> no false positives */
return true;
}
template<typename GroupAccessMode,typename F>
auto for_all_elements(GroupAccessMode access_mode,F f)const
->decltype(f(nullptr),void())
@@ -1544,7 +1656,7 @@ private:
auto mask=this->match_really_occupied(pg,last);
while(mask){
auto n=unchecked_countr_zero(mask);
if(!f(pg,n,p+n))return false;
if(BOOST_LIKELY(is_really_occupied(pg,n))&&!f(pg,n,p+n))return false;
mask&=mask-1;
}
}
@@ -1579,7 +1691,7 @@ private:
auto mask=this->match_really_occupied(&g,last);
while(mask){
auto n=unchecked_countr_zero(mask);
f(&g,n,p+n);
if(BOOST_LIKELY(is_really_occupied(&g,n)))f(&g,n,p+n);
mask&=mask-1;
}
}
@@ -1601,7 +1713,7 @@ private:
auto mask=this->match_really_occupied(&g,last);
while(mask){
auto n=unchecked_countr_zero(mask);
if(!f(p+n))return false;
if(BOOST_LIKELY(is_really_occupied(&g,n))&&!f(p+n))return false;
mask&=mask-1;
}
return true;
+16 -61
View File
@@ -1,8 +1,7 @@
/* Common base for Boost.Unordered open-addressing tables.
*
* Copyright 2022-2024 Joaquin M Lopez Munoz.
* Copyright 2022-2023 Joaquin M Lopez Munoz.
* Copyright 2023 Christian Mazakas.
* Copyright 2024 Braden Ganetsky.
* 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)
@@ -23,7 +22,6 @@
#include <boost/core/pointer_traits.hpp>
#include <boost/cstdint.hpp>
#include <boost/predef.h>
#include <boost/unordered/detail/allocator_constructed.hpp>
#include <boost/unordered/detail/narrow_cast.hpp>
#include <boost/unordered/detail/mulx.hpp>
#include <boost/unordered/detail/static_assert.hpp>
@@ -977,12 +975,7 @@ struct arrays_holder
arrays_holder(arrays_holder const&);
arrays_holder& operator=(arrays_holder const&)=delete;
~arrays_holder()
{
if(!released_){
arrays_.delete_(typename Arrays::allocator_type(al_),arrays_);
}
}
~arrays_holder(){if(!released_)arrays_.delete_(al_,arrays_);}
const Arrays& release()
{
@@ -1227,15 +1220,22 @@ class alloc_cted_insert_type
emplace_type,typename TypePolicy::element_type
>::type;
using alloc_cted = allocator_constructed<Allocator, insert_type, TypePolicy>;
alloc_cted val;
alignas(insert_type) unsigned char storage[sizeof(insert_type)];
Allocator al;
public:
alloc_cted_insert_type(const Allocator& al_,Args&&... args):val{al_,std::forward<Args>(args)...}
alloc_cted_insert_type(const Allocator& al_,Args&&... args):al{al_}
{
TypePolicy::construct(al,data(),std::forward<Args>(args)...);
}
insert_type& value(){return val.value();}
~alloc_cted_insert_type()
{
TypePolicy::destroy(al,data());
}
insert_type* data(){return reinterpret_cast<insert_type*>(&storage);}
insert_type& value(){return *data();}
};
template<typename TypePolicy,typename Allocator,typename... Args>
@@ -1245,51 +1245,6 @@ alloc_make_insert_type(const Allocator& al,Args&&... args)
return {al,std::forward<Args>(args)...};
}
template <typename TypePolicy, typename Allocator, typename KFwdRef,
typename = void>
class alloc_cted_or_fwded_key_type
{
using key_type = typename TypePolicy::key_type;
allocator_constructed<Allocator, key_type, TypePolicy> val;
public:
alloc_cted_or_fwded_key_type(const Allocator& al_, KFwdRef k)
: val(al_, std::forward<KFwdRef>(k))
{
}
key_type&& move_or_fwd() { return std::move(val.value()); }
};
template <typename TypePolicy, typename Allocator, typename KFwdRef>
class alloc_cted_or_fwded_key_type<TypePolicy, Allocator, KFwdRef,
typename std::enable_if<
is_similar<KFwdRef, typename TypePolicy::key_type>::value>::type>
{
// This specialization acts as a forwarding-reference wrapper
BOOST_UNORDERED_STATIC_ASSERT(std::is_reference<KFwdRef>::value);
KFwdRef ref;
public:
alloc_cted_or_fwded_key_type(const Allocator&, KFwdRef k)
: ref(std::forward<KFwdRef>(k))
{
}
KFwdRef move_or_fwd() { return std::forward<KFwdRef>(ref); }
};
template <typename Container>
using is_map =
std::integral_constant<bool, !std::is_same<typename Container::key_type,
typename Container::value_type>::value>;
template <typename Container, typename K>
using is_emplace_kv_able = std::integral_constant<bool,
is_map<Container>::value &&
(is_similar<K, typename Container::key_type>::value ||
is_complete_and_move_constructible<typename Container::key_type>::value)>;
/* table_core. The TypePolicy template parameter is used to generate
* instantiations suitable for either maps or sets, and introduces non-standard
* init_type and element_type:
@@ -1307,7 +1262,7 @@ using is_emplace_kv_able = std::integral_constant<bool,
*
* - TypePolicy::construct and TypePolicy::destroy are used for the
* construction and destruction of the internal types: value_type,
* init_type, element_type, and key_type.
* init_type and element_type.
*
* - TypePolicy::move is used to provide move semantics for the internal
* types used by the container during rehashing and emplace. These types
@@ -1979,7 +1934,7 @@ private:
arrays_type new_arrays(std::size_t n)const
{
return arrays_type::new_(typename arrays_type::allocator_type(al()),n);
return arrays_type::new_(al(),n);
}
arrays_type new_arrays_for_growth()const
@@ -2000,7 +1955,7 @@ private:
void delete_arrays(arrays_type& arrays_)noexcept
{
arrays_type::delete_(typename arrays_type::allocator_type(al()),arrays_);
arrays_type::delete_(al(),arrays_);
}
arrays_holder_type make_arrays(std::size_t n)const
@@ -1,5 +1,4 @@
// Copyright (C) 2023 Christian Mazakas
// Copyright (C) 2024 Braden Ganetsky
// 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)
@@ -57,12 +56,6 @@ namespace boost {
boost::allocator_construct(al, p, std::forward<Args>(args)...);
}
template <class A, class... Args>
static void construct(A& al, key_type* p, Args&&... args)
{
boost::allocator_construct(al, p, std::forward<Args>(args)...);
}
template <class A> static void destroy(A& al, init_type* p) noexcept
{
boost::allocator_destroy(al, p);
@@ -72,11 +65,6 @@ namespace boost {
{
boost::allocator_destroy(al, p);
}
template <class A> static void destroy(A& al, key_type* p) noexcept
{
boost::allocator_destroy(al, p);
}
};
} // namespace foa
} // namespace detail
@@ -1,5 +1,4 @@
// Copyright (C) 2023 Christian Mazakas
// Copyright (C) 2024 Braden Ganetsky
// 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)
@@ -83,12 +82,6 @@ namespace boost {
boost::allocator_construct(al, p, std::forward<Args>(args)...);
}
template <class A, class... Args>
static void construct(A& al, key_type* p, Args&&... args)
{
boost::allocator_construct(al, p, std::forward<Args>(args)...);
}
template <class A, class... Args>
static void construct(A& al, element_type* p, Args&&... args)
{
@@ -116,11 +109,6 @@ namespace boost {
boost::allocator_destroy(al, p);
}
template <class A> static void destroy(A& al, key_type* p) noexcept
{
boost::allocator_destroy(al, p);
}
template <class A>
static void destroy(A& al, element_type* p) noexcept
{
+1 -26
View File
@@ -2,7 +2,6 @@
*
* Copyright 2022-2023 Joaquin M Lopez Munoz.
* Copyright 2023 Christian Mazakas.
* Copyright 2024 Braden Ganetsky.
* 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)
@@ -19,7 +18,6 @@
#include <boost/core/serialization.hpp>
#include <boost/unordered/detail/foa/core.hpp>
#include <boost/unordered/detail/serialize_tracked_address.hpp>
#include <boost/unordered/detail/type_traits.hpp>
#include <cstddef>
#include <iterator>
#include <memory>
@@ -402,34 +400,11 @@ public:
template<typename... Args>
BOOST_FORCEINLINE std::pair<iterator,bool> emplace(Args&&... args)
{
alloc_cted_insert_type<type_policy,Allocator,Args...> x(
auto x=alloc_make_insert_type<type_policy>(
this->al(),std::forward<Args>(args)...);
return emplace_impl(type_policy::move(x.value()));
}
/* Optimization for value_type and init_type, to avoid constructing twice */
template <typename T>
BOOST_FORCEINLINE typename std::enable_if<
detail::is_similar_to_any<T, value_type, init_type>::value,
std::pair<iterator, bool> >::type
emplace(T&& x)
{
return emplace_impl(std::forward<T>(x));
}
/* Optimizations for maps for (k,v) to avoid eagerly constructing value */
template <typename K, typename V>
BOOST_FORCEINLINE
typename std::enable_if<is_emplace_kv_able<table, K>::value,
std::pair<iterator, bool> >::type
emplace(K&& k, V&& v)
{
alloc_cted_or_fwded_key_type<type_policy, Allocator, K&&> x(
this->al(), std::forward<K>(k));
return emplace_impl(
try_emplace_args_t{}, x.move_or_fwd(), std::forward<V>(v));
}
template<typename Key,typename... Args>
BOOST_FORCEINLINE std::pair<iterator,bool> try_emplace(
Key&& x,Args&&... args)
@@ -1,8 +1,7 @@
// Copyright (C) 2003-2004 Jeremy B. Maitin-Shepard.
// Copyright (C) 2005-2016 Daniel James
// Copyright (C) 2022-2024 Joaquin M Lopez Munoz.
// Copyright (C) 2022-2023 Joaquin M Lopez Munoz.
// Copyright (C) 2022-2023 Christian Mazakas
// Copyright (C) 2024 Braden Ganetsky
//
// 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)
@@ -15,7 +14,6 @@
#pragma once
#endif
#include <boost/unordered/detail/allocator_constructed.hpp>
#include <boost/unordered/detail/fca.hpp>
#include <boost/unordered/detail/opt_storage.hpp>
#include <boost/unordered/detail/serialize_tracked_address.hpp>
@@ -40,7 +38,6 @@
#include <stdexcept>
#include <type_traits>
#include <utility>
#include <tuple> // std::forward_as_tuple
namespace boost {
namespace tuples {
@@ -106,10 +103,6 @@ namespace boost {
template <class T> no_key(T const&) {}
};
struct converting_key
{
};
namespace func {
template <class T> inline void ignore_unused_variable_warning(T const&)
{
@@ -1366,14 +1359,14 @@ namespace boost {
}
table(std::size_t num_buckets, hasher const& hf, key_equal const& eq,
value_allocator const& a)
node_allocator_type const& a)
: functions(hf, eq), size_(0), mlf_(1.0f), max_load_(0),
buckets_(num_buckets, a)
{
recalculate_max_load();
}
table(table const& x, value_allocator const& a)
table(table const& x, node_allocator_type const& a)
: functions(x), size_(0), mlf_(x.mlf_), max_load_(0),
buckets_(x.size_, a)
{
@@ -1388,7 +1381,7 @@ namespace boost {
x.max_load_ = 0;
}
table(table& x, value_allocator const& a,
table(table& x, node_allocator_type const& a,
boost::unordered::detail::move_tag m)
: functions(x, m), size_(0), mlf_(x.mlf_), max_load_(0),
buckets_(x.bucket_count(), a)
@@ -1919,16 +1912,6 @@ namespace boost {
}
}
template <typename K, typename V>
emplace_return emplace_unique(converting_key, K&& k, V&& v)
{
using alloc_cted = allocator_constructed<node_allocator_type,
typename Types::key_type>;
alloc_cted key(this->node_alloc(), std::forward<K>(k));
return emplace_unique(
key.value(), std::move(key.value()), std::forward<V>(v));
}
template <typename Key> emplace_return try_emplace_unique(Key&& k)
{
std::size_t key_hash = this->hash(k);
@@ -2722,7 +2705,7 @@ namespace boost {
inline void table<Types>::rehash_impl(std::size_t num_buckets)
{
bucket_array_type new_buckets(
num_buckets, buckets_.get_allocator());
num_buckets, buckets_.get_node_allocator());
BOOST_TRY
{
@@ -2851,13 +2834,9 @@ namespace boost {
}
template <class Arg1, class Arg2>
static typename std::conditional<
(is_similar<Arg1, key_type>::value ||
is_complete_and_move_constructible<key_type>::value),
converting_key, no_key>::type
extract(Arg1 const&, Arg2 const&)
static no_key extract(Arg1 const&, Arg2 const&)
{
return {};
return no_key();
}
template <class Arg1, class Arg2, class Arg3, class... Args>
-2
View File
@@ -1,7 +1,6 @@
// Copyright (C) 2005-2016 Daniel James
// Copyright (C) 2022 Christian Mazakas
// Copyright (C) 2024 Braden Ganetsky
// 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)
@@ -19,7 +18,6 @@ namespace boost {
typedef std::pair<K const, M> value_type;
typedef H hasher;
typedef P key_equal;
typedef K key_type;
typedef K const const_key_type;
typedef
@@ -1,5 +1,4 @@
// Copyright (C) 2022-2023 Christian Mazakas
// Copyright (C) 2024 Braden Ganetsky
//
// 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)
@@ -49,20 +48,6 @@ namespace boost {
template <typename... Ts> using void_t = typename make_void<Ts...>::type;
template <class T, class = void> struct is_complete : std::false_type
{
};
template <class T>
struct is_complete<T, void_t<int[sizeof(T)]> > : std::true_type
{
};
template <class T>
using is_complete_and_move_constructible =
typename std::conditional<is_complete<T>::value,
std::is_move_constructible<T>, std::false_type>::type;
#if BOOST_WORKAROUND(BOOST_LIBSTDCXX_VERSION, < 50000)
/* std::is_trivially_default_constructible not provided */
template <class T>
@@ -162,23 +147,6 @@ namespace boost {
!std::is_convertible<Key, const_iterator>::value;
};
template <class T>
using remove_cvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
template <class T, class U>
using is_similar = std::is_same<remove_cvref_t<T>, remove_cvref_t<U> >;
template <class, class...> struct is_similar_to_any : std::false_type
{
};
template <class T, class U, class... Us>
struct is_similar_to_any<T, U, Us...>
: std::conditional<is_similar<T, U>::value, is_similar<T, U>,
is_similar_to_any<T, Us...> >::type
{
};
#if BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES
// https://eel.is/c++draft/container.requirements#container.alloc.reqmts-34
// https://eel.is/c++draft/container.requirements#unord.req.general-243
+8 -12
View File
@@ -1,7 +1,6 @@
// 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)
@@ -159,7 +158,7 @@ namespace boost {
allocator_type get_allocator() const noexcept
{
return allocator_type(table_.node_alloc());
return table_.node_alloc();
}
// // iterators
@@ -255,15 +254,12 @@ namespace boost {
node_type extract(const_iterator position)
{
return node_type(
table_.extract_by_iterator_unique(position),
allocator_type(table_.node_alloc()));
table_.extract_by_iterator_unique(position), table_.node_alloc());
}
node_type extract(const key_type& k)
{
return node_type(
table_.extract_by_key_impl(k),
allocator_type(table_.node_alloc()));
return node_type(table_.extract_by_key_impl(k), table_.node_alloc());
}
template <class Key>
@@ -272,9 +268,8 @@ namespace boost {
node_type>::type
extract(Key&& k)
{
return node_type(
table_.extract_by_key_impl(std::forward<Key>(k)),
allocator_type(table_.node_alloc()));
return node_type(table_.extract_by_key_impl(std::forward<Key>(k)),
table_.node_alloc());
}
insert_return_type insert(node_type&& np)
@@ -811,7 +806,7 @@ namespace boost {
allocator_type get_allocator() const noexcept
{
return allocator_type(table_.node_alloc());
return table_.node_alloc();
}
// iterators
@@ -2057,7 +2052,8 @@ namespace boost {
unordered_multimap<K, T, H, P, A>::find(CompatibleKey const& k,
CompatibleHash const& hash, CompatiblePredicate const& eq) const
{
return table_.transparent_find(k, hash, eq);
return const_iterator(
table_.find_node_impl(table::policy::apply_hash(hash, k), k, eq));
}
template <class K, class T, class H, class P, class A>
+5 -11
View File
@@ -1,7 +1,6 @@
// 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)
@@ -155,7 +154,7 @@ namespace boost {
allocator_type get_allocator() const noexcept
{
return allocator_type(table_.node_alloc());
return table_.node_alloc();
}
// iterators
@@ -253,15 +252,12 @@ namespace boost {
node_type extract(const_iterator position)
{
return node_type(
table_.extract_by_iterator_unique(position),
allocator_type(table_.node_alloc()));
table_.extract_by_iterator_unique(position), table_.node_alloc());
}
node_type extract(const key_type& k)
{
return node_type(
table_.extract_by_key_impl(k),
allocator_type(table_.node_alloc()));
return node_type(table_.extract_by_key_impl(k), table_.node_alloc());
}
template <class Key>
@@ -270,9 +266,7 @@ namespace boost {
node_type>::type
extract(const Key& k)
{
return node_type(
table_.extract_by_key_impl(k),
allocator_type(table_.node_alloc()));
return node_type(table_.extract_by_key_impl(k), table_.node_alloc());
}
insert_return_type insert(node_type&& np)
@@ -653,7 +647,7 @@ namespace boost {
allocator_type get_allocator() const noexcept
{
return allocator_type(table_.node_alloc());
return table_.node_alloc();
}
// iterators
-5
View File
@@ -85,14 +85,12 @@ local FCA_TESTS =
contains_tests
copy_tests
deduction_tests
emplace_smf_tests
emplace_tests
equality_tests
equivalent_keys_tests
erase_equiv_tests
erase_if
erase_tests
explicit_alloc_ctor_tests
extract_tests
find_tests
fwd_map_test
@@ -203,10 +201,8 @@ local FOA_TESTS =
assign_tests
insert_tests
insert_hint_tests
emplace_smf_tests
emplace_tests
erase_tests
explicit_alloc_ctor_tests
merge_tests
find_tests
at_tests
@@ -329,7 +325,6 @@ local CFOA_TESTS =
rw_spinlock_test7
rw_spinlock_test8
reentrancy_check_test
explicit_alloc_ctor_tests
;
for local test in $(CFOA_TESTS)
+22 -12
View File
@@ -968,9 +968,11 @@ namespace {
BOOST_TEST_EQ(x.key_eq(), key_equal(2));
BOOST_TEST_EQ(
raii::copy_constructor, value_type_cardinality * reference_cont.size());
BOOST_TEST_EQ(raii::destructor, 0u);
BOOST_TEST_EQ(raii::move_constructor, 0u);
raii::copy_constructor, value_type_cardinality * values.size());
BOOST_TEST_EQ(
raii::destructor, value_type_cardinality * values.size());
BOOST_TEST_EQ(
raii::move_constructor, value_type_cardinality * reference_cont.size());
BOOST_TEST_EQ(raii::copy_assignment, 0u);
BOOST_TEST_EQ(raii::move_assignment, 0u);
}
@@ -996,9 +998,11 @@ namespace {
BOOST_TEST_EQ(flat.key_eq(), key_equal(2));
BOOST_TEST_EQ(
raii::copy_constructor, value_type_cardinality * reference_cont.size());
BOOST_TEST_EQ(raii::destructor, 0u);
BOOST_TEST_EQ(raii::move_constructor, 0u);
raii::copy_constructor, value_type_cardinality * values.size());
BOOST_TEST_EQ(
raii::destructor, value_type_cardinality * values.size());
BOOST_TEST_EQ(
raii::move_constructor, value_type_cardinality * reference_cont.size());
BOOST_TEST_EQ(raii::copy_assignment, 0u);
BOOST_TEST_EQ(raii::move_assignment, 0u);
}
@@ -1026,11 +1030,14 @@ namespace {
BOOST_TEST_EQ(x.key_eq(), key_equal(2));
BOOST_TEST_EQ(
raii::copy_constructor, value_type_cardinality * reference_cont.size());
raii::copy_constructor, value_type_cardinality * values.size());
BOOST_TEST_EQ(
raii::destructor, value_type_cardinality * reference_cont.size());
raii::destructor,
value_type_cardinality * values.size() +
value_type_cardinality * reference_cont.size());
BOOST_TEST_EQ(
raii::move_constructor, value_type_cardinality * reference_cont.size());
raii::move_constructor,
2 * value_type_cardinality * reference_cont.size());
BOOST_TEST_EQ(raii::copy_assignment, 0u);
BOOST_TEST_EQ(raii::move_assignment, 0u);
}
@@ -1056,11 +1063,14 @@ namespace {
BOOST_TEST_EQ(flat.key_eq(), key_equal(2));
BOOST_TEST_EQ(
raii::copy_constructor, value_type_cardinality * reference_cont.size());
raii::copy_constructor, value_type_cardinality * values.size());
BOOST_TEST_EQ(
raii::destructor, value_type_cardinality * reference_cont.size());
raii::destructor,
value_type_cardinality * values.size() +
value_type_cardinality * reference_cont.size());
BOOST_TEST_EQ(
raii::move_constructor, value_type_cardinality * reference_cont.size());
raii::move_constructor,
2 * value_type_cardinality * reference_cont.size());
BOOST_TEST_EQ(raii::copy_assignment, 0u);
BOOST_TEST_EQ(raii::move_assignment, 0u);
}
+12 -15
View File
@@ -712,9 +712,9 @@ namespace {
BOOST_TEST_EQ(raii::default_constructor, 0u);
BOOST_TEST_EQ(
raii::copy_constructor, value_type_cardinality * init_list.size() / 2u);
raii::copy_constructor, value_type_cardinality * init_list.size());
BOOST_TEST_EQ(
raii::move_constructor, 0u);
raii::move_constructor, value_type_cardinality * 11u);
}
check_raii_counts();
@@ -730,9 +730,9 @@ namespace {
BOOST_TEST_EQ(raii::default_constructor, 0u);
BOOST_TEST_EQ(
raii::copy_constructor, value_type_cardinality * init_list.size() / 2u);
raii::copy_constructor, value_type_cardinality * init_list.size());
BOOST_TEST_EQ(
raii::move_constructor, 0u);
raii::move_constructor, value_type_cardinality * 11u);
}
check_raii_counts();
@@ -748,9 +748,9 @@ namespace {
BOOST_TEST_EQ(raii::default_constructor, 0u);
BOOST_TEST_EQ(
raii::copy_constructor, value_type_cardinality * init_list.size() / 2u);
raii::copy_constructor, value_type_cardinality * init_list.size());
BOOST_TEST_EQ(
raii::move_constructor, 0u);
raii::move_constructor, value_type_cardinality * 11u);
}
check_raii_counts();
@@ -766,9 +766,9 @@ namespace {
BOOST_TEST_EQ(raii::default_constructor, 0u);
BOOST_TEST_EQ(
raii::copy_constructor, value_type_cardinality * init_list.size() / 2u);
raii::copy_constructor, value_type_cardinality * init_list.size());
BOOST_TEST_EQ(
raii::move_constructor, 0u);
raii::move_constructor, value_type_cardinality * 11u);
}
check_raii_counts();
}
@@ -867,9 +867,6 @@ namespace {
template <class X, class GF>
void flat_constructor(X*, GF gen_factory, test::random_generator rg)
{
using value_type = typename X::value_type;
static constexpr auto value_type_cardinality =
value_cardinality<value_type>::value;
using allocator_type = typename X::allocator_type;
auto gen = gen_factory.template get<X>();
@@ -889,8 +886,8 @@ namespace {
auto const old_cc = +raii::copy_constructor;
BOOST_TEST_EQ(old_dc, 0u);
BOOST_TEST_EQ(old_mc, 0u);
BOOST_TEST_EQ(old_cc, value_type_cardinality * flat.size());
BOOST_TEST_GT(old_mc, 0u);
BOOST_TEST_GT(old_cc, 0u);
X x(std::move(flat));
@@ -934,8 +931,8 @@ namespace {
auto const old_cc = +raii::copy_constructor;
BOOST_TEST_EQ(old_dc, 0u);
BOOST_TEST_EQ(old_mc, 0u);
BOOST_TEST_EQ(old_cc, 2u * value_type_cardinality * x.size());
BOOST_TEST_GT(old_mc, 0u);
BOOST_TEST_GT(old_cc, 0u);
flat_container<X> flat(std::move(x));
+11 -256
View File
@@ -1,11 +1,9 @@
// Copyright (C) 2023 Christian Mazakas
// Copyright (C) 2023 Joaquin M Lopez Munoz
// Copyright (C) 2024 Braden Ganetsky
// 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)
#include "helpers.hpp"
#include "../helpers/count.hpp"
#include <boost/unordered/concurrent_flat_map.hpp>
#include <boost/unordered/concurrent_flat_set.hpp>
@@ -53,7 +51,7 @@ namespace {
struct lvalue_emplacer_type
{
template <class T, class X> void call_impl(std::vector<T>& values, X& x)
template <class T, class X> void operator()(std::vector<T>& values, X& x)
{
static constexpr auto value_type_cardinality =
value_cardinality<typename X::value_type>::value;
@@ -68,33 +66,28 @@ namespace {
}
});
BOOST_TEST_EQ(num_inserts, x.size());
BOOST_TEST_EQ(
raii::default_constructor, value_type_cardinality * values.size());
std::uint64_t const default_constructors = value_type_cardinality == 2
? values.size() + num_inserts
: values.size();
BOOST_TEST_EQ(raii::default_constructor, default_constructors);
BOOST_TEST_EQ(raii::copy_constructor, 0u);
BOOST_TEST_GE(raii::move_constructor, value_type_cardinality * x.size());
BOOST_TEST_EQ(raii::copy_constructor, 0u);
BOOST_TEST_EQ(raii::copy_assignment, 0u);
BOOST_TEST_EQ(raii::move_assignment, 0u);
}
template <class T, class X> void operator()(std::vector<T>& values, X& x)
{
static constexpr auto value_type_cardinality =
value_cardinality<typename X::value_type>::value;
call_impl(values, x);
BOOST_TEST_GE(raii::move_constructor, value_type_cardinality * x.size());
}
} lvalue_emplacer;
struct norehash_lvalue_emplacer_type : public lvalue_emplacer_type
{
template <class T, class X> void operator()(std::vector<T>& values, X& x)
{
static constexpr auto value_type_cardinality =
value_cardinality<typename X::value_type>::value;
x.reserve(values.size());
lvalue_emplacer_type::call_impl(values, x);
BOOST_TEST_EQ(raii::move_constructor, x.size());
lvalue_emplacer_type::operator()(values, x);
BOOST_TEST_EQ(raii::move_constructor, value_type_cardinality * x.size());
}
} norehash_lvalue_emplacer;
@@ -177,74 +170,6 @@ namespace {
}
} lvalue_emplace_or_visit;
struct copy_emplacer_type
{
template <class T, class X> void operator()(std::vector<T>& values, X& x)
{
static constexpr auto value_type_cardinality =
value_cardinality<typename X::value_type>::value;
std::atomic<std::uint64_t> num_inserts{0};
thread_runner(values, [&x, &num_inserts](boost::span<T> s) {
for (auto const& r : s) {
bool b = x.emplace(r);
if (b) {
++num_inserts;
}
}
});
BOOST_TEST_EQ(num_inserts, x.size());
BOOST_TEST_EQ(raii::default_constructor, 0u);
BOOST_TEST_EQ(raii::copy_constructor, value_type_cardinality * x.size());
BOOST_TEST_GT(raii::move_constructor, 0u);
BOOST_TEST_EQ(raii::copy_assignment, 0u);
BOOST_TEST_EQ(raii::move_assignment, 0u);
}
} copy_emplacer;
struct move_emplacer_type
{
template <class T, class X> void operator()(std::vector<T>& values, X& x)
{
static constexpr auto value_type_cardinality =
value_cardinality<typename X::value_type>::value;
std::atomic<std::uint64_t> num_inserts{0};
thread_runner(values, [&x, &num_inserts](boost::span<T> s) {
for (auto& r : s) {
bool b = x.emplace(std::move(r));
if (b) {
++num_inserts;
}
}
});
BOOST_TEST_EQ(num_inserts, x.size());
BOOST_TEST_EQ(raii::default_constructor, 0u);
#if defined(BOOST_MSVC)
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#endif
if (std::is_same<T, typename X::value_type>::value &&
!std::is_same<typename X::key_type,
typename X::value_type>::value) { // map value_type can only be
// copied, no move
BOOST_TEST_EQ(raii::copy_constructor, x.size());
} else {
BOOST_TEST_EQ(raii::copy_constructor, 0u);
}
#if defined(BOOST_MSVC)
#pragma warning(pop) // C4127
#endif
BOOST_TEST_GT(raii::move_constructor, value_type_cardinality * x.size());
BOOST_TEST_EQ(raii::copy_assignment, 0u);
BOOST_TEST_EQ(raii::move_assignment, 0u);
}
} move_emplacer;
template <class X, class GF, class F>
void emplace(X*, GF gen_factory, F emplacer, test::random_generator rg)
{
@@ -295,179 +220,9 @@ UNORDERED_TEST(
((map)(set))
((value_type_generator_factory)(init_type_generator_factory))
((lvalue_emplacer)(norehash_lvalue_emplacer)
(lvalue_emplace_or_cvisit)(lvalue_emplace_or_visit)(copy_emplacer)(move_emplacer))
(lvalue_emplace_or_cvisit)(lvalue_emplace_or_visit))
((default_generator)(sequential)(limited_range)))
// clang-format on
namespace {
using converting_key_type = basic_raii<struct converting_key_tag_>;
using converting_value_type = basic_raii<struct converting_value_tag_>;
class counted_key_type : public basic_raii<struct counted_key_tag_>
{
public:
using basic_raii::basic_raii;
counted_key_type() = default;
counted_key_type(const converting_key_type& k) : counted_key_type(k.x_) {}
};
class counted_value_type : public basic_raii<struct counted_value_tag_>
{
public:
using basic_raii::basic_raii;
counted_value_type() = default;
counted_value_type(const converting_value_type& v)
: counted_value_type(v.x_)
{
}
};
void reset_counts()
{
counted_key_type::reset_counts();
counted_value_type::reset_counts();
converting_key_type::reset_counts();
converting_value_type::reset_counts();
}
using test::smf_count;
template <class T> smf_count count_for()
{
return test::smf_count{
(int)T::default_constructor.load(std::memory_order_relaxed),
(int)T::copy_constructor.load(std::memory_order_relaxed),
(int)T::move_constructor.load(std::memory_order_relaxed),
(int)T::copy_assignment.load(std::memory_order_relaxed),
(int)T::move_assignment.load(std::memory_order_relaxed),
(int)T::destructor.load(std::memory_order_relaxed)};
}
enum emplace_kind
{
copy,
move
};
enum emplace_status
{
fail,
success
};
struct counted_key_checker_type
{
using key_type = counted_key_type;
void operator()(emplace_kind kind, emplace_status status)
{
int copies = (kind == copy && status == success) ? 1 : 0;
int moves = (kind == move && status == success) ? 1 : 0;
BOOST_TEST_EQ(
count_for<counted_key_type>(), (smf_count{0, copies, moves, 0, 0, 0}));
}
} counted_key_checker;
struct converting_key_checker_type
{
using key_type = converting_key_type;
void operator()(emplace_kind, emplace_status status)
{
int moves = (status == success) ? 1 : 0;
BOOST_TEST_EQ(
count_for<counted_key_type>(), (smf_count{1, 0, moves, 0, 0, 1}));
}
} converting_key_checker;
struct counted_value_checker_type
{
using mapped_type = counted_value_type;
void operator()(emplace_kind kind, emplace_status status)
{
int copies = (kind == copy && status == success) ? 1 : 0;
int moves = (kind == move && status == success) ? 1 : 0;
BOOST_TEST_EQ(count_for<counted_value_type>(),
(smf_count{0, copies, moves, 0, 0, 0}));
}
} counted_value_checker;
struct converting_value_checker_type
{
using mapped_type = converting_value_type;
void operator()(emplace_kind, emplace_status status)
{
int ctors = (status == success) ? 1 : 0;
BOOST_TEST_EQ(
count_for<counted_value_type>(), (smf_count{ctors, 0, 0, 0, 0, 0}));
}
} converting_value_checker;
template <class X, class KC, class VC>
void emplace_map_key_value(
X*, emplace_kind kind, KC key_checker, VC value_checker)
{
using container = X;
using key_type = typename KC::key_type;
using mapped_type = typename VC::mapped_type;
container x;
key_type key{};
key_type key2 = key;
mapped_type value{};
mapped_type value2 = value;
{
reset_counts();
auto ret = (kind == copy) ? x.emplace(key, value)
: x.emplace(std::move(key), std::move(value));
BOOST_TEST_EQ(ret, true);
key_checker(kind, success);
value_checker(kind, success);
BOOST_TEST_EQ(
count_for<converting_key_type>(), (smf_count{0, 0, 0, 0, 0, 0}));
BOOST_TEST_EQ(
count_for<converting_value_type>(), (smf_count{0, 0, 0, 0, 0, 0}));
}
{
reset_counts();
bool ret = x.emplace(key2, value2);
BOOST_TEST_EQ(ret, false);
key_checker(kind, fail);
value_checker(kind, fail);
BOOST_TEST_EQ(
count_for<converting_key_type>(), (smf_count{0, 0, 0, 0, 0, 0}));
BOOST_TEST_EQ(
count_for<converting_value_type>(), (smf_count{0, 0, 0, 0, 0, 0}));
}
{
reset_counts();
bool ret = x.emplace(std::move(key2), std::move(value2));
BOOST_TEST_EQ(ret, false);
key_checker(kind, fail);
value_checker(kind, fail);
BOOST_TEST_EQ(
count_for<converting_key_type>(), (smf_count{0, 0, 0, 0, 0, 0}));
BOOST_TEST_EQ(
count_for<converting_value_type>(), (smf_count{0, 0, 0, 0, 0, 0}));
}
}
boost::unordered::concurrent_flat_map<counted_key_type, counted_value_type>*
test_counted_flat_map = {};
} // namespace
// clang-format off
UNORDERED_TEST(
emplace_map_key_value,
((test_counted_flat_map))
((copy)(move))
((counted_key_checker)(converting_key_checker))
((counted_value_checker)(converting_value_checker))
)
// clang-format on
RUN_TESTS()
+1 -1
View File
@@ -33,7 +33,7 @@ static std::size_t const num_threads =
std::atomic_bool should_throw{false};
constexpr std::uint32_t throw_threshold = 2300;
constexpr std::uint32_t throw_threshold = 2500;
constexpr std::uint32_t alloc_throw_threshold = 10;
void enable_exceptions() { should_throw = true; }
-6
View File
@@ -1,6 +0,0 @@
// Copyright 2024 Joaquin M Lopez Muoz.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at htT://www.boost.org/LICENSE_1_0.txt)
#define BOOST_UNORDERED_CFOA_TESTS
#include "../unordered/explicit_alloc_ctor_tests.cpp"
+23 -46
View File
@@ -1,6 +1,5 @@
// Copyright (C) 2023 Christian Mazakas
// Copyright (C) 2023 Joaquin M Lopez Munoz
// Copyright (C) 2024 Braden Ganetsky
// 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)
@@ -208,8 +207,7 @@ template <class T> struct stateful_allocator2
bool operator!=(stateful_allocator2 const& rhs) const { return x_ != rhs.x_; }
};
template <class Tag>
struct basic_raii
struct raii
{
static std::atomic<std::uint32_t> default_constructor;
static std::atomic<std::uint32_t> copy_constructor;
@@ -221,17 +219,17 @@ struct basic_raii
int x_ = -1;
basic_raii() { ++default_constructor; }
basic_raii(int const x) : x_{x} { ++default_constructor; }
basic_raii(basic_raii const& rhs) : x_{rhs.x_} { ++copy_constructor; }
basic_raii(basic_raii&& rhs) noexcept : x_{rhs.x_}
raii() { ++default_constructor; }
raii(int const x) : x_{x} { ++default_constructor; }
raii(raii const& rhs) : x_{rhs.x_} { ++copy_constructor; }
raii(raii&& rhs) noexcept : x_{rhs.x_}
{
rhs.x_ = -1;
++move_constructor;
}
~basic_raii() { ++destructor; }
~raii() { ++destructor; }
basic_raii& operator=(basic_raii const& rhs)
raii& operator=(raii const& rhs)
{
++copy_assignment;
if (this != &rhs) {
@@ -240,7 +238,7 @@ struct basic_raii
return *this;
}
basic_raii& operator=(basic_raii&& rhs) noexcept
raii& operator=(raii&& rhs) noexcept
{
++move_assignment;
if (this != &rhs) {
@@ -250,37 +248,37 @@ struct basic_raii
return *this;
}
friend bool operator==(basic_raii const& lhs, basic_raii const& rhs)
friend bool operator==(raii const& lhs, raii const& rhs)
{
return lhs.x_ == rhs.x_;
}
friend bool operator!=(basic_raii const& lhs, basic_raii const& rhs)
friend bool operator!=(raii const& lhs, raii const& rhs)
{
return !(lhs == rhs);
}
friend bool operator==(basic_raii const& lhs, int const x) { return lhs.x_ == x; }
friend bool operator!=(basic_raii const& lhs, int const x)
friend bool operator==(raii const& lhs, int const x) { return lhs.x_ == x; }
friend bool operator!=(raii const& lhs, int const x)
{
return !(lhs.x_ == x);
}
friend bool operator==(int const x, basic_raii const& rhs) { return rhs.x_ == x; }
friend bool operator==(int const x, raii const& rhs) { return rhs.x_ == x; }
friend bool operator!=(int const x, basic_raii const& rhs)
friend bool operator!=(int const x, raii const& rhs)
{
return !(rhs.x_ == x);
}
friend std::ostream& operator<<(std::ostream& os, basic_raii const& rhs)
friend std::ostream& operator<<(std::ostream& os, raii const& rhs)
{
os << "{ x_: " << rhs.x_ << " }";
return os;
}
friend std::ostream& operator<<(
std::ostream& os, std::pair<basic_raii const, basic_raii> const& rhs)
std::ostream& os, std::pair<raii const, raii> const& rhs)
{
os << "pair<" << rhs.first << ", " << rhs.second << ">";
return os;
@@ -296,30 +294,16 @@ struct basic_raii
move_assignment = 0;
}
friend void swap(basic_raii& lhs, basic_raii& rhs) { std::swap(lhs.x_, rhs.x_); }
friend void swap(raii& lhs, raii& rhs) { std::swap(lhs.x_, rhs.x_); }
};
template <class Tag> std::atomic<std::uint32_t> basic_raii<Tag>::default_constructor(0);
template <class Tag> std::atomic<std::uint32_t> basic_raii<Tag>::copy_constructor(0);
template <class Tag> std::atomic<std::uint32_t> basic_raii<Tag>::move_constructor(0);
template <class Tag> std::atomic<std::uint32_t> basic_raii<Tag>::destructor(0);
template <class Tag> std::atomic<std::uint32_t> basic_raii<Tag>::copy_assignment(0);
template <class Tag> std::atomic<std::uint32_t> basic_raii<Tag>::move_assignment(0);
std::atomic<std::uint32_t> raii::default_constructor{0};
std::atomic<std::uint32_t> raii::copy_constructor{0};
std::atomic<std::uint32_t> raii::move_constructor{0};
std::atomic<std::uint32_t> raii::destructor{0};
std::atomic<std::uint32_t> raii::copy_assignment{0};
std::atomic<std::uint32_t> raii::move_assignment{0};
struct raii_tag_
{
};
class raii : public basic_raii<raii_tag_>
{
using basic_raii::basic_raii;
};
template <class Tag>
std::size_t hash_value(basic_raii<Tag> const& r) noexcept
{
boost::hash<int> hasher;
return hasher(r.x_);
}
std::size_t hash_value(raii const& r) noexcept
{
boost::hash<int> hasher;
@@ -327,13 +311,6 @@ std::size_t hash_value(raii const& r) noexcept
}
namespace std {
template <class Tag> struct hash<basic_raii<Tag>>
{
std::size_t operator()(basic_raii<Tag> const& r) const noexcept
{
return hash_value(r);
}
};
template <> struct hash<raii>
{
std::size_t operator()(raii const& r) const noexcept
+4 -11
View File
@@ -156,9 +156,6 @@ namespace {
BOOST_WORKAROUND(BOOST_GCC_VERSION, < 50500)
// some versions of old gcc have trouble eliding copies here
// https://godbolt.org/z/Ebo6TbvaG
#elif BOOST_WORKAROUND(BOOST_GCC_VERSION, >= 40900) && \
BOOST_WORKAROUND(BOOST_GCC_VERSION, < 50000)
// seemingly same problem, though the snippet above does not reveal it
#else
BOOST_TEST_EQ(raii::copy_constructor, 0u);
#endif
@@ -491,10 +488,8 @@ namespace {
BOOST_TEST_EQ(
raii::default_constructor, value_type_cardinality * values2.size());
#if (BOOST_WORKAROUND(BOOST_GCC_VERSION, >= 50300) && \
BOOST_WORKAROUND(BOOST_GCC_VERSION, < 50500)) || \
(BOOST_WORKAROUND(BOOST_GCC_VERSION, >= 40900) && \
BOOST_WORKAROUND(BOOST_GCC_VERSION, < 50000))
#if BOOST_WORKAROUND(BOOST_GCC_VERSION, >= 50300) && \
BOOST_WORKAROUND(BOOST_GCC_VERSION, < 50500)
// skip test
#else
BOOST_TEST_EQ(raii::copy_constructor, 0u);
@@ -530,10 +525,8 @@ namespace {
BOOST_TEST_EQ(
raii::default_constructor, value_type_cardinality * values2.size());
#if (BOOST_WORKAROUND(BOOST_GCC_VERSION, >= 50300) && \
BOOST_WORKAROUND(BOOST_GCC_VERSION, < 50500)) || \
(BOOST_WORKAROUND(BOOST_GCC_VERSION, >= 40900) && \
BOOST_WORKAROUND(BOOST_GCC_VERSION, < 50000))
#if BOOST_WORKAROUND(BOOST_GCC_VERSION, >= 50300) && \
BOOST_WORKAROUND(BOOST_GCC_VERSION, < 50500)
// skip test
#else
BOOST_TEST_EQ(raii::copy_constructor, 0u);
+1 -111
View File
@@ -1,6 +1,5 @@
// Copyright 2008-2009 Daniel James.
// Copyright 2024 Braden Ganetsky.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or move at http://www.boost.org/LICENSE_1_0.txt)
@@ -8,7 +7,6 @@
#define BOOST_UNORDERED_TEST_HELPERS_COUNT_HEAD
#include <boost/core/lightweight_test.hpp>
#include <boost/container_hash/hash.hpp>
namespace test {
struct object_count
@@ -86,114 +84,6 @@ namespace test {
return global_object_count.constructions - constructions_;
}
};
struct smf_count
{
int default_constructions = 0;
int copy_constructions = 0;
int move_constructions = 0;
int copy_assignments = 0;
int move_assignments = 0;
int destructions = 0;
#if (BOOST_CXX_VERSION < 201402L) || (defined(_MSC_VER) && _MSC_VER < 1910)
smf_count() = default;
smf_count(int default_constructions_, int copy_constructions_,
int move_constructions_, int copy_assignments_, int move_assignments_,
int destructions_)
: default_constructions(default_constructions_),
copy_constructions(copy_constructions_),
move_constructions(move_constructions_),
copy_assignments(copy_assignments_),
move_assignments(move_assignments_), destructions(destructions_)
{
}
#endif
void reset() { *this = smf_count(); }
void default_construct() { ++default_constructions; }
void copy_construct() { ++copy_constructions; }
void move_construct() { ++move_constructions; }
void copy_assign() { ++copy_assignments; }
void move_assign() { ++move_assignments; }
void destruct() { ++destructions; }
friend bool operator==(smf_count const& lhs, smf_count const& rhs)
{
return lhs.default_constructions == rhs.default_constructions &&
lhs.copy_constructions == rhs.copy_constructions &&
lhs.move_constructions == rhs.move_constructions &&
lhs.copy_assignments == rhs.copy_assignments &&
lhs.move_assignments == rhs.move_assignments &&
lhs.destructions == rhs.destructions;
}
friend std::ostream& operator<<(std::ostream& out, smf_count const& c)
{
out << "[default_constructions: " << c.default_constructions
<< ", copy_constructions: " << c.copy_constructions
<< ", move_constructions: " << c.move_constructions
<< ", copy_assignments: " << c.copy_assignments
<< ", move_assignments: " << c.move_assignments
<< ", destructions: " << c.destructions << "]";
return out;
}
};
template <class Tag> class smf_counted_object
{
public:
static smf_count count;
static void reset_count() { count.reset(); }
smf_counted_object(int index) : smf_counted_object() { index_ = index; }
smf_counted_object() : index_(++running_index)
{
count.default_construct();
}
smf_counted_object(smf_counted_object const& rhs) : index_(rhs.index_)
{
count.copy_construct();
}
smf_counted_object(smf_counted_object&& rhs) noexcept : index_(rhs.index_)
{
count.move_construct();
}
smf_counted_object& operator=(smf_counted_object const& rhs)
{
count.copy_assign();
index_ = rhs.index_;
return *this;
}
smf_counted_object& operator=(smf_counted_object&& rhs) noexcept
{
count.move_assign();
index_ = rhs.index_;
return *this;
}
~smf_counted_object() { count.destruct(); }
friend bool operator==(
smf_counted_object const& lhs, smf_counted_object const& rhs)
{
return lhs.index_ == rhs.index_;
}
friend std::size_t hash_value(smf_counted_object const& x)
{
return boost::hash<int>()(x.index_);
}
int index_;
private:
static int running_index;
};
template <class Tag> smf_count smf_counted_object<Tag>::count = {};
template <class Tag> int smf_counted_object<Tag>::running_index = 0;
} // namespace test
}
#endif
-6
View File
@@ -21,10 +21,4 @@
#include "postfix.hpp"
// clang-format on
#if defined(BOOST_LIBSTDCXX_VERSION)
#if BOOST_LIBSTDCXX_VERSION < 60000
#define BOOST_UNORDERED_NO_INIT_TYPE_TESTS
#endif
#endif
#endif
-377
View File
@@ -1,377 +0,0 @@
//
// Copyright 2023-2024 Braden Ganetsky.
// 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)
#include "../helpers/unordered.hpp"
#include "../helpers/count.hpp"
#include "../helpers/test.hpp"
namespace emplace_smf_tests {
using test::smf_count;
using test::smf_counted_object;
using converting_key = smf_counted_object<struct cvt_key_tag_>;
using converting_value = smf_counted_object<struct cvt_value_tag_>;
class counted_key : public smf_counted_object<struct key_tag_>
{
public:
using smf_counted_object::smf_counted_object;
counted_key() = default;
counted_key(const converting_key& k) : counted_key(k.index_) {}
};
class counted_value : public smf_counted_object<struct value_tag_>
{
public:
using smf_counted_object::smf_counted_object;
counted_value() = default;
counted_value(const converting_value& v) : counted_value(v.index_) {}
};
class immovable_key : public smf_counted_object<struct imm_key_tag_>
{
public:
using smf_counted_object::smf_counted_object;
immovable_key(immovable_key&&) = delete;
immovable_key& operator=(immovable_key&&) = delete;
};
class immovable_value : public smf_counted_object<struct imm_value_tag_>
{
public:
using smf_counted_object::smf_counted_object;
immovable_value(immovable_value&&) = delete;
immovable_value& operator=(immovable_value&&) = delete;
};
void reset_counts()
{
counted_key::reset_count();
counted_value::reset_count();
converting_key::reset_count();
converting_value::reset_count();
immovable_key::reset_count();
immovable_value::reset_count();
}
#ifdef BOOST_UNORDERED_FOA_TESTS
static boost::unordered_flat_map<counted_key, counted_value>* test_smf_map;
static boost::unordered_node_map<counted_key, counted_value>*
test_smf_node_map;
static boost::unordered_flat_set<counted_value>* test_smf_set;
static boost::unordered_node_set<counted_value>* test_smf_node_set;
#define EMPLACE_SMF_TESTS_MAP_ARGS ((test_smf_map)(test_smf_node_map))
#define EMPLACE_SMF_TESTS_SET_ARGS ((test_smf_set)(test_smf_node_set))
#else
static boost::unordered_map<counted_key, counted_value>* test_smf_map;
static boost::unordered_set<counted_value>* test_smf_set;
#define EMPLACE_SMF_TESTS_MAP_ARGS ((test_smf_map))
#define EMPLACE_SMF_TESTS_SET_ARGS ((test_smf_set))
#endif
template <class X> static void emplace_smf_value_type_map(X*)
{
using container = X;
using value_type = typename container::value_type;
container x;
{
value_type val{counted_key{}, counted_value{}};
x.clear();
reset_counts();
x.emplace(val);
BOOST_TEST_EQ(counted_key::count, (smf_count{0, 1, 0, 0, 0, 0}));
BOOST_TEST_EQ(counted_value::count, (smf_count{0, 1, 0, 0, 0, 0}));
}
{
value_type val{counted_key{}, counted_value{}};
x.clear();
reset_counts();
x.emplace(std::move(val));
BOOST_TEST_EQ(counted_key::count, (smf_count{0, 1, 0, 0, 0, 0}));
BOOST_TEST_EQ(counted_value::count, (smf_count{0, 0, 1, 0, 0, 0}));
}
{
x.clear();
reset_counts();
x.emplace(value_type{counted_key{}, counted_value{}});
BOOST_TEST_EQ(counted_key::count, (smf_count{1, 1, 1, 0, 0, 2}));
BOOST_TEST_EQ(counted_value::count, (smf_count{1, 0, 2, 0, 0, 2}));
}
{
counted_key key{};
counted_value value{};
x.clear();
reset_counts();
x.emplace(value_type{std::move(key), std::move(value)});
BOOST_TEST_EQ(counted_key::count, (smf_count{0, 1, 1, 0, 0, 1}));
BOOST_TEST_EQ(counted_value::count, (smf_count{0, 0, 2, 0, 0, 1}));
}
}
UNORDERED_TEST(emplace_smf_value_type_map, EMPLACE_SMF_TESTS_MAP_ARGS)
template <class X> static void emplace_smf_init_type_map(X*)
{
using container = X;
#ifdef BOOST_UNORDERED_FOA_TESTS
using init_type = typename container::init_type;
#else
using raw_key =
typename std::remove_const<typename container::key_type>::type;
using init_type = std::pair<raw_key, typename container::mapped_type>;
#endif
container x;
{
init_type val{counted_key{}, counted_value{}};
x.clear();
reset_counts();
x.emplace(val);
BOOST_TEST_EQ(counted_key::count, (smf_count{0, 1, 0, 0, 0, 0}));
BOOST_TEST_EQ(counted_value::count, (smf_count{0, 1, 0, 0, 0, 0}));
}
{
init_type val{counted_key{}, counted_value{}};
x.clear();
reset_counts();
x.emplace(std::move(val));
BOOST_TEST_EQ(counted_key::count, (smf_count{0, 0, 1, 0, 0, 0}));
BOOST_TEST_EQ(counted_value::count, (smf_count{0, 0, 1, 0, 0, 0}));
}
{
x.clear();
reset_counts();
x.emplace(init_type{counted_key{}, counted_value{}});
BOOST_TEST_EQ(counted_key::count, (smf_count{1, 0, 2, 0, 0, 2}));
BOOST_TEST_EQ(counted_value::count, (smf_count{1, 0, 2, 0, 0, 2}));
}
{
counted_key key{};
counted_value value{};
x.clear();
reset_counts();
x.emplace(init_type{std::move(key), std::move(value)});
BOOST_TEST_EQ(counted_key::count, (smf_count{0, 0, 2, 0, 0, 1}));
BOOST_TEST_EQ(counted_value::count, (smf_count{0, 0, 2, 0, 0, 1}));
}
}
UNORDERED_TEST(emplace_smf_init_type_map, EMPLACE_SMF_TESTS_MAP_ARGS)
template <class X> static void emplace_smf_value_type_set(X*)
{
using container = X;
using value_type = typename container::value_type;
#ifdef BOOST_UNORDERED_FOA_TESTS
BOOST_STATIC_ASSERT(
std::is_same<value_type, typename container::init_type>::value);
#endif
BOOST_STATIC_ASSERT(std::is_same<value_type, counted_value>::value);
container x;
{
counted_value val{};
x.clear();
reset_counts();
x.emplace(val);
BOOST_TEST_EQ(counted_value::count, (smf_count{0, 1, 0, 0, 0, 0}));
}
{
counted_value val{};
x.clear();
reset_counts();
x.emplace(std::move(val));
BOOST_TEST_EQ(counted_value::count, (smf_count{0, 0, 1, 0, 0, 0}));
}
{
x.clear();
reset_counts();
x.emplace(counted_value{});
BOOST_TEST_EQ(counted_value::count, (smf_count{1, 0, 1, 0, 0, 1}));
}
}
UNORDERED_TEST(emplace_smf_value_type_set, EMPLACE_SMF_TESTS_SET_ARGS)
enum emplace_kind
{
copy,
move
};
enum emplace_status
{
fail,
success
};
struct counted_key_checker_type
{
using key_type = counted_key;
void operator()(emplace_kind kind, emplace_status status)
{
int copies = (kind == copy && status == success) ? 1 : 0;
int moves = (kind == move && status == success) ? 1 : 0;
BOOST_TEST_EQ(counted_key::count, (smf_count{0, copies, moves, 0, 0, 0}));
}
} counted_key_checker;
struct converting_key_checker_type
{
using key_type = converting_key;
void operator()(emplace_kind, emplace_status status)
{
int moves = (status == success) ? 1 : 0;
BOOST_TEST_EQ(counted_key::count, (smf_count{1, 0, moves, 0, 0, 1}));
}
} converting_key_checker;
struct counted_value_checker_type
{
using mapped_type = counted_value;
void operator()(emplace_kind kind, emplace_status status)
{
int copies = (kind == copy && status == success) ? 1 : 0;
int moves = (kind == move && status == success) ? 1 : 0;
BOOST_TEST_EQ(
counted_value::count, (smf_count{0, copies, moves, 0, 0, 0}));
}
} counted_value_checker;
struct converting_value_checker_type
{
using mapped_type = converting_value;
void operator()(emplace_kind, emplace_status status)
{
int ctors = (status == success) ? 1 : 0;
BOOST_TEST_EQ(counted_value::count, (smf_count{ctors, 0, 0, 0, 0, 0}));
}
} converting_value_checker;
template <class X, class KC, class VC>
static void emplace_smf_key_value_map(
X*, emplace_kind kind, KC key_checker, VC value_checker)
{
using container = X;
using key_type = typename KC::key_type;
using mapped_type = typename VC::mapped_type;
container x;
key_type key{};
key_type key2 = key;
mapped_type value{};
mapped_type value2 = value;
{
reset_counts();
auto ret = (kind == copy) ? x.emplace(key, value)
: x.emplace(std::move(key), std::move(value));
BOOST_TEST_EQ(ret.second, true);
key_checker(kind, success);
value_checker(kind, success);
BOOST_TEST_EQ(converting_key::count, (smf_count{0, 0, 0, 0, 0, 0}));
BOOST_TEST_EQ(converting_value::count, (smf_count{0, 0, 0, 0, 0, 0}));
}
{
reset_counts();
auto ret = x.emplace(key2, value2);
BOOST_TEST_EQ(ret.second, false);
key_checker(kind, fail);
value_checker(kind, fail);
BOOST_TEST_EQ(converting_key::count, (smf_count{0, 0, 0, 0, 0, 0}));
BOOST_TEST_EQ(converting_value::count, (smf_count{0, 0, 0, 0, 0, 0}));
}
{
reset_counts();
auto ret = x.emplace(std::move(key2), std::move(value2));
BOOST_TEST_EQ(ret.second, false);
key_checker(kind, fail);
value_checker(kind, fail);
BOOST_TEST_EQ(converting_key::count, (smf_count{0, 0, 0, 0, 0, 0}));
BOOST_TEST_EQ(converting_value::count, (smf_count{0, 0, 0, 0, 0, 0}));
}
}
// clang-format off
UNORDERED_TEST(
emplace_smf_key_value_map,
EMPLACE_SMF_TESTS_MAP_ARGS
((copy)(move))
((counted_key_checker)(converting_key_checker))
((counted_value_checker)(converting_value_checker))
)
// clang-format on
template <class X> static void emplace_smf_key_value_map_immovable_key(X*)
{
#ifndef BOOST_UNORDERED_NO_INIT_TYPE_TESTS
using container = X;
BOOST_STATIC_ASSERT(
std::is_same<immovable_key, typename X::key_type>::value);
using mapped_type = typename X::mapped_type;
container x;
{
reset_counts();
auto ret = x.emplace(0, 0);
BOOST_TEST_EQ(ret.second, true);
BOOST_TEST_EQ(immovable_key::count, (smf_count{1, 0, 0, 0, 0, 0}));
BOOST_TEST_EQ(mapped_type::count, (smf_count{1, 0, 0, 0, 0, 0}));
}
{
reset_counts();
auto ret = x.emplace(0, 1);
BOOST_TEST_EQ(ret.second, false);
BOOST_TEST_EQ(immovable_key::count, (smf_count{1, 0, 0, 0, 0, 1}));
BOOST_TEST_EQ(mapped_type::count, (smf_count{1, 0, 0, 0, 0, 1}));
}
#endif
}
#ifdef BOOST_UNORDERED_FOA_TESTS
static boost::unordered_node_map<immovable_key, counted_value>*
test_smf_node_map_immovable_key_counted_value;
static boost::unordered_node_map<immovable_key, immovable_value>*
test_smf_node_map_immovable_key_immovable_value;
#define EMPLACE_SMF_TESTS_MAP_IMMOVABLE_ARGS \
((test_smf_node_map_immovable_key_counted_value)(test_smf_node_map_immovable_key_immovable_value))
#else
static boost::unordered_map<immovable_key, counted_value>*
test_smf_map_immovable_key_counted_value;
static boost::unordered_map<immovable_key, immovable_value>*
test_smf_map_immovable_key_immovable_value;
#define EMPLACE_SMF_TESTS_MAP_IMMOVABLE_ARGS \
((test_smf_map_immovable_key_counted_value)(test_smf_map_immovable_key_immovable_value))
#endif
// clang-format off
UNORDERED_TEST(
emplace_smf_key_value_map_immovable_key,
EMPLACE_SMF_TESTS_MAP_IMMOVABLE_ARGS
)
// clang-format on
} // namespace emplace_smf_tests
RUN_TESTS()
@@ -1,152 +0,0 @@
// Copyright 2024 Joaquin M Lopez Muoz.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at htT://www.boost.org/LICENSE_1_0.txt)
#ifdef BOOST_UNORDERED_CFOA_TESTS
#include <boost/unordered/concurrent_flat_map.hpp>
#include <boost/unordered/concurrent_flat_set.hpp>
#else
#include "../helpers/unordered.hpp"
#endif
#include "../helpers/test.hpp"
#include <boost/type_traits/make_void.hpp>
#include <memory>
#include <vector>
template <class T> struct explicit_allocator
{
typedef T value_type;
explicit_allocator() {}
template <class U>
explicit explicit_allocator(const explicit_allocator<U>&) {}
template<class U>
bool operator==(explicit_allocator<U> const &) const noexcept
{
return true;
}
template<class U>
bool operator!=(explicit_allocator<U> const &) const noexcept
{
return false;
}
T* allocate(std::size_t n)
{
return std::allocator<T>().allocate(n);
}
void deallocate(T* p, std::size_t n)
{
std::allocator<T>().deallocate(p, n);
}
};
template<typename Container,typename = void> struct has_extract:
std::false_type {};
template<typename Container>
struct has_extract<
Container, boost::void_t<typename Container::insert_return_type>
>: std::true_type {};
template <class Container> void test_explicit_alloc_ctor_extract(
Container&, std::false_type)
{
}
template <class Container> void test_explicit_alloc_ctor_extract(
Container& c, std::true_type)
{
auto n = c.extract(c.begin());
c.insert(std::move(n));
n = c.extract(typename Container::key_type());
c.insert(std::move(n));
}
template <class Container> void test_explicit_alloc_ctor_extract(Container& c)
{
test_explicit_alloc_ctor_extract(c, has_extract<Container>());
}
template <class Container> void test_explicit_alloc_ctor()
{
using key_type = typename Container::key_type;
using value_type = typename Container::value_type;
using hasher = typename Container::hasher;
using allocator_type = typename Container::allocator_type;
allocator_type al;
std::initializer_list<value_type> il{};
hasher h;
std::vector<value_type> v;
Container c,
c2(0),
c3(v.begin(), v.end()),
c4(c3),
c5(std::move(c4)),
c6(v.begin(), v.end(), al),
c7(al),
c8(c7, al),
c9(std::move(c8), al),
c10(il),
c11(0, al),
c12(0, h, al),
c13(v.begin(), v.end(), 0, al),
c14(v.begin(), v.end(), 0, h, al),
c15(il, al),
c16(il, 0, al),
c17(il, 0, h, al);
value_type x{};
key_type k{};
c = c2;
c = std::move(c2);
c = il;
c.swap(c3);
c.insert(x);
#ifdef BOOST_UNORDERED_CFOA_TESTS
(void) c.visit(k, [](const value_type&) {});
#else
(void) c.find(k);
#endif
test_explicit_alloc_ctor_extract(c);
}
UNORDERED_AUTO_TEST (explicit_alloc_ctor) {
#if defined(BOOST_UNORDERED_CFOA_TESTS)
test_explicit_alloc_ctor<boost::concurrent_flat_map<int, int,
boost::hash<int>, std::equal_to<int>,
explicit_allocator<std::pair<const int, int> > > >();
test_explicit_alloc_ctor<boost::concurrent_flat_set<
int, boost::hash<int>, std::equal_to<int>, explicit_allocator<int> > >();
#elif defined(BOOST_UNORDERED_FOA_TESTS)
test_explicit_alloc_ctor<boost::unordered_flat_map<int, int,
boost::hash<int>, std::equal_to<int>,
explicit_allocator<std::pair<const int, int> > > >();
test_explicit_alloc_ctor<boost::unordered_flat_set<
int, boost::hash<int>, std::equal_to<int>, explicit_allocator<int> > >();
test_explicit_alloc_ctor<boost::unordered_node_map<int, int,
boost::hash<int>, std::equal_to<int>,
explicit_allocator<std::pair<const int, int> > > >();
test_explicit_alloc_ctor<boost::unordered_node_set<
int, boost::hash<int>, std::equal_to<int>, explicit_allocator<int> > >();
#else
test_explicit_alloc_ctor<boost::unordered_map<int, int,
boost::hash<int>, std::equal_to<int>,
explicit_allocator<std::pair<const int, int> > > >();
test_explicit_alloc_ctor<boost::unordered_multimap<int, int,
boost::hash<int>, std::equal_to<int>,
explicit_allocator<std::pair<const int, int> > > >();
test_explicit_alloc_ctor<boost::unordered_set<
int, boost::hash<int>, std::equal_to<int>, explicit_allocator<int> > >();
test_explicit_alloc_ctor<boost::unordered_multiset<
int, boost::hash<int>, std::equal_to<int>, explicit_allocator<int> > >();
#endif
}
RUN_TESTS()
-4
View File
@@ -1,7 +1,6 @@
// Copyright 2006-2009 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)
@@ -113,7 +112,6 @@ namespace find_tests {
typedef typename test::random_values<X>::iterator value_iterator;
test::random_values<X> v(500, generator);
X x(v.begin(), v.end());
X const& x_const = x;
compatible_hash h;
compatible_predicate eq;
@@ -121,7 +119,6 @@ namespace find_tests {
for (value_iterator it = v.begin(), end = v.end(); it != end; ++it) {
typename X::key_type key = test::get_key<X>(*it);
BOOST_TEST(x.find(key) == x.find(compatible_key(key), h, eq));
BOOST_TEST(x_const.find(key) == x_const.find(compatible_key(key), h, eq));
}
test::random_values<X> v2(20, generator);
@@ -129,7 +126,6 @@ namespace find_tests {
for (value_iterator it = v2.begin(), end = v2.end(); it != end; ++it) {
typename X::key_type key = test::get_key<X>(*it);
BOOST_TEST(x.find(key) == x.find(compatible_key(key), h, eq));
BOOST_TEST(x_const.find(key) == x_const.find(compatible_key(key), h, eq));
}
}
@@ -12,6 +12,12 @@
#include <boost/config.hpp>
#if defined(BOOST_LIBSTDCXX_VERSION)
#if BOOST_LIBSTDCXX_VERSION < 60000
#define BOOST_UNORDERED_NO_INIT_TYPE_TESTS
#endif
#endif
struct move_only
{
int x_ = -1;