Commit c27460f2 authored by Mark Santaniello's avatar Mark Santaniello Committed by Facebook Github Bot

bugfix sorted_vector_types allocator-extended c'ctor

Summary: The nested EBO classes were missing the allocator-extended c'ctor.  Fix and add tests to cover this case.

Reviewed By: nbronson

Differential Revision: D17284711

fbshipit-source-id: 6e7e8df83712f018fd6a7558513164f319b1b7f8
parent 835f77cd
......@@ -686,12 +686,20 @@ class sorted_vector_set : detail::growth_policy_wrapper<GrowthPolicy> {
explicit EBO(const Compare& c, const Allocator& alloc) noexcept(
std::is_nothrow_default_constructible<Container>::value)
: Compare(c), cont_(alloc) {}
EBO(const EBO& other, const Allocator& alloc)
noexcept(std::is_nothrow_constructible<
Container,
const Container&,
const Allocator&>::value)
: Compare(static_cast<const Compare&>(other)),
cont_(other.cont_, alloc) {}
EBO(EBO&& other, const Allocator& alloc)
noexcept(std::is_nothrow_constructible<
Container,
Container&&,
const Allocator&>::value)
: Compare(), cont_(std::move(other.cont_), alloc) {}
: Compare(static_cast<Compare&&>(other)),
cont_(std::move(other.cont_), alloc) {}
EBO(const Compare& c, Container&& cont)
noexcept(std::is_nothrow_move_constructible<Container>::value)
: Compare(c), cont_(std::move(cont)) {}
......@@ -1220,12 +1228,20 @@ class sorted_vector_map : detail::growth_policy_wrapper<GrowthPolicy> {
explicit EBO(const value_compare& c, const Allocator& alloc) noexcept(
std::is_nothrow_default_constructible<Container>::value)
: value_compare(c), cont_(alloc) {}
EBO(const EBO& other, const Allocator& alloc)
noexcept(std::is_nothrow_constructible<
Container,
const Container&,
const Allocator&>::value)
: value_compare(static_cast<const value_compare&>(other)),
cont_(other.cont_, alloc) {}
EBO(EBO&& other, const Allocator& alloc)
noexcept(std::is_nothrow_constructible<
Container,
Container&&,
const Allocator&>::value)
: value_compare(Compare()), cont_(std::move(other.cont_), alloc) {}
: value_compare(static_cast<value_compare&&>(other)),
cont_(std::move(other.cont_), alloc) {}
EBO(const Compare& c, Container&& cont)
noexcept(std::is_nothrow_move_constructible<Container>::value)
: value_compare(c), cont_(std::move(cont)) {}
......
......@@ -931,6 +931,62 @@ TEST(SortedVectorTypes, TestPmrAllocatorSimple) {
EXPECT_THROW(m.emplace(42, 42), std::bad_alloc);
}
TEST(SortedVectorTypes, TestPmrCopyConstructSameAlloc) {
namespace pmr = folly::pmr;
set_default_resource(null_memory_resource());
test_resource r;
polymorphic_allocator<std::byte> a1(&r), a2(&r);
EXPECT_EQ(a1, a2);
{
pmr::sorted_vector_set<int> s1(a1);
s1.emplace(42);
pmr::sorted_vector_set<int> s2(s1, a2);
EXPECT_EQ(s1.get_allocator(), s2.get_allocator());
EXPECT_EQ(s2.count(42), 1);
}
{
pmr::sorted_vector_map<int, int> m1(a1);
m1.emplace(42, 42);
pmr::sorted_vector_map<int, int> m2(m1, a2);
EXPECT_EQ(m1.get_allocator(), m2.get_allocator());
EXPECT_EQ(m2.at(42), 42);
}
}
TEST(SortedVectorTypes, TestPmrCopyConstructDifferentAlloc) {
namespace pmr = folly::pmr;
set_default_resource(null_memory_resource());
test_resource r1, r2;
polymorphic_allocator<std::byte> a1(&r1), a2(&r2);
EXPECT_NE(a1, a2);
{
pmr::sorted_vector_set<int> s1(a1);
s1.emplace(42);
pmr::sorted_vector_set<int> s2(s1, a2);
EXPECT_NE(s1.get_allocator(), s2.get_allocator());
EXPECT_EQ(s2.count(42), 1);
}
{
pmr::sorted_vector_map<int, int> m1(a1);
m1.emplace(42, 42);
pmr::sorted_vector_map<int, int> m2(m1, a2);
EXPECT_NE(m1.get_allocator(), m2.get_allocator());
EXPECT_EQ(m2.at(42), 42);
}
}
TEST(SortedVectorTypes, TestPmrMoveConstructSameAlloc) {
namespace pmr = folly::pmr;
......@@ -946,7 +1002,9 @@ TEST(SortedVectorTypes, TestPmrMoveConstructSameAlloc) {
auto d = s1.data();
pmr::sorted_vector_set<int> s2(std::move(s1), a2);
EXPECT_EQ(s1.get_allocator(), s2.get_allocator());
EXPECT_EQ(s2.data(), d);
EXPECT_EQ(s2.count(42), 1);
}
{
......@@ -955,7 +1013,9 @@ TEST(SortedVectorTypes, TestPmrMoveConstructSameAlloc) {
auto d = m1.data();
pmr::sorted_vector_map<int, int> m2(std::move(m1), a2);
EXPECT_EQ(m1.get_allocator(), m2.get_allocator());
EXPECT_EQ(m2.data(), d);
EXPECT_EQ(m2.at(42), 42);
}
}
......@@ -974,7 +1034,9 @@ TEST(SortedVectorTypes, TestPmrMoveConstructDifferentAlloc) {
auto d = s1.data();
pmr::sorted_vector_set<int> s2(std::move(s1), a2);
EXPECT_NE(s1.get_allocator(), s2.get_allocator());
EXPECT_NE(s2.data(), d);
EXPECT_EQ(s2.count(42), 1);
}
{
......@@ -983,7 +1045,9 @@ TEST(SortedVectorTypes, TestPmrMoveConstructDifferentAlloc) {
auto d = m1.data();
pmr::sorted_vector_map<int, int> m2(std::move(m1), a2);
EXPECT_NE(m1.get_allocator(), m2.get_allocator());
EXPECT_NE(m2.data(), d);
EXPECT_EQ(m2.at(42), 42);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment