Skip to content

Commit

Permalink
assigned non-empty std::initializer_lists
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquintides committed Sep 2, 2024
1 parent 48db35c commit cc8b403
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
23 changes: 17 additions & 6 deletions test/cfoa/assign_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <boost/unordered/concurrent_node_map.hpp>
#include <boost/unordered/concurrent_node_set.hpp>

#include <vector>

#if defined(__clang__) && defined(__has_warning)

#if __has_warning("-Wself-assign-overloaded")
Expand Down Expand Up @@ -885,19 +887,26 @@ namespace {
check_raii_counts();
}

template <class X>
void initializer_list_assign_gh276(X*)
template <class X, class GF>
void initializer_list_assign_gh276(
X*, GF gen_factory, test::random_generator rg)
{
// https://github.com/boostorg/unordered/issues/276

using replaced_allocator_container = test::replace_allocator<
X, test::non_default_ctble_allocator<int> >;
using value_type = typename replaced_allocator_container::value_type;
using replaced_allocator_type =
typename replaced_allocator_container::allocator_type;

replaced_allocator_container x(replaced_allocator_type(0));
x = std::initializer_list<value_type>();
auto gen = gen_factory.template get<X>();
auto values = make_random_values(4, [&] { return gen(rg); });

replaced_allocator_container
x(replaced_allocator_type(0)),
y(values.begin(), values.end(), replaced_allocator_type(0));

x = {values[0], values[1], values[2], values[3]};
BOOST_TEST(x == y);
}

template <class X, class GF>
Expand Down Expand Up @@ -1132,7 +1141,9 @@ UNORDERED_TEST(

UNORDERED_TEST(
initializer_list_assign_gh276,
((test_map)(test_node_map)(test_set)(test_node_set)))
((test_map)(test_node_map)(test_set)(test_node_set))
((value_type_generator_factory))
((default_generator)))

UNORDERED_TEST(
insert_and_assign,
Expand Down
15 changes: 12 additions & 3 deletions test/unordered/assign_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "../helpers/tracker.hpp"
#include "../helpers/equivalent.hpp"

#include <vector>

#if defined(BOOST_MSVC)
#pragma warning(disable : 4127) // conditional expression is constant
#endif
Expand Down Expand Up @@ -295,14 +297,21 @@ namespace assign_tests {
{
// https://github.com/boostorg/unordered/issues/276

using value_type = typename T::value_type;
using replaced_allocator_container = test::replace_allocator<
T, test::non_default_ctble_allocator<int> >;
using value_type = typename replaced_allocator_container::value_type;
using replaced_allocator_type =
typename replaced_allocator_container::allocator_type;

replaced_allocator_container x(replaced_allocator_type(0));
x = std::initializer_list<value_type>();
test::random_values<T> v(4, generator);
std::vector<value_type> vv(v.begin(), v.end());

replaced_allocator_container
x(replaced_allocator_type(0)),
y(vv.begin(), vv.begin() + 4, replaced_allocator_type(0));

x = {vv[0], vv[1], vv[2], vv[3]};
BOOST_TEST(x == y);
}
}

Expand Down

0 comments on commit cc8b403

Please sign in to comment.