Skip to content

Commit f1e2fa3

Browse files
authored
Fix issue with constructing an FOA container from a class with a template conversion operator (#334)
* Add missing compile-only tests in CMake * Rewrite the FOA containers' CFOA constructors so that a class with a template conversion operator does not instantiate the CFOA container * Rewrite the CFOA containers' FOA constructors so that a class with a template conversion operator does not instantiate the FOA container
1 parent 4fd90dc commit f1e2fa3

12 files changed

Lines changed: 132 additions & 18 deletions

include/boost/unordered/concurrent_flat_map.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*
33
* Copyright 2023 Christian Mazakas.
44
* Copyright 2023-2026 Joaquin M Lopez Munoz.
5+
* Copyright 2026 Braden Ganetsky
56
* Distributed under the Boost Software License, Version 1.0.
67
* (See accompanying file LICENSE_1_0.txt or copy at
78
* http://www.boost.org/LICENSE_1_0.txt)
@@ -189,10 +190,10 @@ namespace boost {
189190
{
190191
}
191192

192-
193-
template <bool avoid_explicit_instantiation = true>
193+
template <typename Key2,
194+
typename std::enable_if<std::is_same<Key, Key2>::value, int>::type = 0>
194195
concurrent_flat_map(
195-
unordered_flat_map<Key, T, Hash, Pred, Allocator>&& other)
196+
unordered_flat_map<Key2, T, Hash, Pred, Allocator>&& other)
196197
: table_(std::move(other.table_))
197198
{
198199
}

include/boost/unordered/concurrent_flat_set.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*
33
* Copyright 2023 Christian Mazakas.
44
* Copyright 2023-2026 Joaquin M Lopez Munoz.
5+
* Copyright 2026 Braden Ganetsky
56
* Distributed under the Boost Software License, Version 1.0.
67
* (See accompanying file LICENSE_1_0.txt or copy at
78
* http://www.boost.org/LICENSE_1_0.txt)
@@ -186,10 +187,10 @@ namespace boost {
186187
{
187188
}
188189

189-
190-
template <bool avoid_explicit_instantiation = true>
190+
template <typename Key2,
191+
typename std::enable_if<std::is_same<Key, Key2>::value, int>::type = 0>
191192
concurrent_flat_set(
192-
unordered_flat_set<Key, Hash, Pred, Allocator>&& other)
193+
unordered_flat_set<Key2, Hash, Pred, Allocator>&& other)
193194
: table_(std::move(other.table_))
194195
{
195196
}

include/boost/unordered/concurrent_node_map.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*
33
* Copyright 2023 Christian Mazakas.
44
* Copyright 2023-2026 Joaquin M Lopez Munoz.
5+
* Copyright 2026 Braden Ganetsky
56
* Distributed under the Boost Software License, Version 1.0.
67
* (See accompanying file LICENSE_1_0.txt or copy at
78
* http://www.boost.org/LICENSE_1_0.txt)
@@ -197,9 +198,10 @@ namespace boost {
197198
{
198199
}
199200

200-
template <bool avoid_explicit_instantiation = true>
201+
template <typename Key2,
202+
typename std::enable_if<std::is_same<Key, Key2>::value, int>::type = 0>
201203
concurrent_node_map(
202-
unordered_node_map<Key, T, Hash, Pred, Allocator>&& other)
204+
unordered_node_map<Key2, T, Hash, Pred, Allocator>&& other)
203205
: table_(std::move(other.table_))
204206
{
205207
}

include/boost/unordered/concurrent_node_set.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*
33
* Copyright 2023 Christian Mazakas.
44
* Copyright 2023-2026 Joaquin M Lopez Munoz.
5+
* Copyright 2026 Braden Ganetsky
56
* Distributed under the Boost Software License, Version 1.0.
67
* (See accompanying file LICENSE_1_0.txt or copy at
78
* http://www.boost.org/LICENSE_1_0.txt)
@@ -194,9 +195,10 @@ namespace boost {
194195
{
195196
}
196197

197-
template <bool avoid_explicit_instantiation = true>
198+
template <typename Key2,
199+
typename std::enable_if<std::is_same<Key, Key2>::value, int>::type = 0>
198200
concurrent_node_set(
199-
unordered_node_set<Key, Hash, Pred, Allocator>&& other)
201+
unordered_node_set<Key2, Hash, Pred, Allocator>&& other)
200202
: table_(std::move(other.table_))
201203
{
202204
}

include/boost/unordered/unordered_flat_map.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (C) 2022-2023 Christian Mazakas
22
// Copyright (C) 2024-2025 Joaquin M Lopez Munoz
3+
// Copyright (C) 2026 Braden Ganetsky
34
// Distributed under the Boost Software License, Version 1.0. (See accompanying
45
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
56

@@ -182,9 +183,10 @@ namespace boost {
182183
{
183184
}
184185

185-
template <bool avoid_explicit_instantiation = true>
186+
template <typename Key2,
187+
typename std::enable_if<std::is_same<Key, Key2>::value, int>::type = 0>
186188
unordered_flat_map(
187-
concurrent_flat_map<Key, T, Hash, KeyEqual, Allocator>&& other)
189+
concurrent_flat_map<Key2, T, Hash, KeyEqual, Allocator>&& other)
188190
: table_(std::move(other.table_))
189191
{
190192
}

include/boost/unordered/unordered_flat_set.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (C) 2022-2023 Christian Mazakas
22
// Copyright (C) 2024-2025 Joaquin M Lopez Munoz
3+
// Copyright (C) 2026 Braden Ganetsky
34
// Distributed under the Boost Software License, Version 1.0. (See accompanying
45
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
56

@@ -178,9 +179,10 @@ namespace boost {
178179
{
179180
}
180181

181-
template <bool avoid_explicit_instantiation = true>
182+
template <typename Key2,
183+
typename std::enable_if<std::is_same<Key, Key2>::value, int>::type = 0>
182184
unordered_flat_set(
183-
concurrent_flat_set<Key, Hash, KeyEqual, Allocator>&& other)
185+
concurrent_flat_set<Key2, Hash, KeyEqual, Allocator>&& other)
184186
: table_(std::move(other.table_))
185187
{
186188
}

include/boost/unordered/unordered_node_map.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (C) 2022-2023 Christian Mazakas
22
// Copyright (C) 2024-2025 Joaquin M Lopez Munoz
3+
// Copyright (C) 2026 Braden Ganetsky
34
// Distributed under the Boost Software License, Version 1.0. (See accompanying
45
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
56

@@ -189,9 +190,10 @@ namespace boost {
189190
{
190191
}
191192

192-
template <bool avoid_explicit_instantiation = true>
193+
template <typename Key2,
194+
typename std::enable_if<std::is_same<Key, Key2>::value, int>::type = 0>
193195
unordered_node_map(
194-
concurrent_node_map<Key, T, Hash, KeyEqual, Allocator>&& other)
196+
concurrent_node_map<Key2, T, Hash, KeyEqual, Allocator>&& other)
195197
: table_(std::move(other.table_))
196198
{
197199
}

include/boost/unordered/unordered_node_set.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (C) 2022-2023 Christian Mazakas
22
// Copyright (C) 2024-2025 Joaquin M Lopez Munoz
3+
// Copyright (C) 2026 Braden Ganetsky
34
// Distributed under the Boost Software License, Version 1.0. (See accompanying
45
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
56

@@ -187,9 +188,10 @@ namespace boost {
187188
{
188189
}
189190

190-
template <bool avoid_explicit_instantiation = true>
191+
template <typename Key2,
192+
typename std::enable_if<std::is_same<Key, Key2>::value, int>::type = 0>
191193
unordered_node_set(
192-
concurrent_node_set<Key, Hash, KeyEqual, Allocator>&& other)
194+
concurrent_node_set<Key2, Hash, KeyEqual, Allocator>&& other)
193195
: table_(std::move(other.table_))
194196
{
195197
}

test/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,13 @@ cfoa_tests(SOURCES cfoa/rw_spinlock_test6.cpp)
163163
cfoa_tests(SOURCES cfoa/rw_spinlock_test7.cpp)
164164
cfoa_tests(SOURCES cfoa/rw_spinlock_test8.cpp)
165165

166+
# Compile tests
167+
168+
fca_tests(TYPE compile NAME explicit_instantiation_tests SOURCES unordered/explicit_instantiation_tests.cpp)
169+
foa_tests(TYPE compile NAME explicit_instantiation_tests SOURCES unordered/explicit_instantiation_tests.cpp)
170+
cfoa_tests(TYPE compile NAME explicit_instantiation_tests SOURCES cfoa/explicit_instantiation_tests.cpp)
171+
172+
foa_tests(TYPE compile NAME conversion_operator_tests SOURCES unordered/conversion_operator_tests.cpp)
173+
cfoa_tests(TYPE compile NAME conversion_operator_tests SOURCES cfoa/conversion_operator_tests.cpp)
174+
166175
endif()

test/Jamfile.v2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ compile unordered/explicit_instantiation_tests.cpp :
166166
compile unordered/explicit_instantiation_tests.cpp : <define>BOOST_UNORDERED_FOA_TESTS : foa_explicit_instantiation_tests ;
167167
compile cfoa/explicit_instantiation_tests.cpp : : cfoa_explicit_instantiation_tests ;
168168

169+
compile unordered/conversion_operator_tests.cpp : <define>BOOST_UNORDERED_FOA_TESTS : foa_conversion_operator_tests ;
170+
compile cfoa/conversion_operator_tests.cpp : : cfoa_conversion_operator_tests ;
171+
169172
local FCA_EXCEPTION_TESTS =
170173
constructor_exception_tests
171174
copy_exception_tests

0 commit comments

Comments
 (0)