Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ int main(int, char**) {
std::vector<char, test_allocator<char>> vs({2, 2, 1}, test_allocator<char>(7));
using M = std::flat_map<int, char, C, decltype(ks), decltype(vs)>;
auto mo = M(ks, vs, C(5));
auto m = M({{3, 3}, {4, 4}, {5, 5}}, C(3), test_allocator<int>(2));
auto m = M({{3, static_cast<char>(3)}, {4, static_cast<char>(4)}, {5, static_cast<char>(5)}},
C(3),
test_allocator<int>(2));
m = mo;

assert(m.key_comp() == C(5));
Expand All @@ -54,7 +56,9 @@ int main(int, char**) {
auto vs = Vs({2, 2, 1}, other_allocator<char>(7));
using M = std::flat_map<int, char, C, Ks, Vs>;
auto mo = M(Ks(ks, other_allocator<int>(6)), Vs(vs, other_allocator<int>(7)), C(5));
auto m = M({{3, 3}, {4, 4}, {5, 5}}, C(3), other_allocator<int>(2));
auto m = M({{3, static_cast<char>(3)}, {4, static_cast<char>(4)}, {5, static_cast<char>(5)}},
C(3),
other_allocator<int>(2));
m = mo;

assert(m.key_comp() == C(5));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ using PC = std::pair<const int, long>;

void test_copy() {
{
std::flat_map<long, short> source = {{1, 2}, {2, 3}};
std::flat_map<long, short> source = {{1, static_cast<short>(2)}, {2, static_cast<short>(3)}};
std::flat_map s(source);
ASSERT_SAME_TYPE(decltype(s), decltype(source));
assert(s == source);
}
{
std::flat_map<long, short, std::greater<long>> source = {{1, 2}, {2, 3}};
std::flat_map<long, short, std::greater<long>> source = {{1, static_cast<short>(2)}, {2, static_cast<short>(3)}};
std::flat_map s{source}; // braces instead of parens
ASSERT_SAME_TYPE(decltype(s), decltype(source));
assert(s == source);
}
{
std::flat_map<long, short, std::greater<long>> source = {{1, 2}, {2, 3}};
std::flat_map<long, short, std::greater<long>> source = {{1, static_cast<short>(2)}, {2, static_cast<short>(3)}};
std::flat_map s(source, std::allocator<int>());
ASSERT_SAME_TYPE(decltype(s), decltype(source));
assert(s == source);
Expand All @@ -55,7 +55,11 @@ void test_containers() {
std::deque<short, test_allocator<short>> vs({1, 2, 1, 4, 5}, test_allocator<int>(0, 43));
std::deque<int, test_allocator<int>> sorted_ks({1, 2, 3, INT_MAX}, test_allocator<int>(0, 42));
std::deque<short, test_allocator<short>> sorted_vs({1, 2, 5, 4}, test_allocator<int>(0, 43));
const std::pair<int, short> expected[] = {{1, 1}, {2, 2}, {3, 5}, {INT_MAX, 4}};
const std::pair<int, short> expected[] = {
{1, static_cast<short>(1)},
{2, static_cast<short>(2)},
{3, static_cast<short>(5)},
{INT_MAX, static_cast<short>(4)}};
{
std::flat_map s(ks, vs);

Expand Down Expand Up @@ -95,7 +99,11 @@ void test_containers_compare() {
std::deque<short, test_allocator<short>> vs({1, 2, 1, 4, 5}, test_allocator<int>(0, 43));
std::deque<int, test_allocator<int>> sorted_ks({INT_MAX, 3, 2, 1}, test_allocator<int>(0, 42));
std::deque<short, test_allocator<short>> sorted_vs({4, 5, 2, 1}, test_allocator<int>(0, 43));
const std::pair<int, short> expected[] = {{INT_MAX, 4}, {3, 5}, {2, 2}, {1, 1}};
const std::pair<int, short> expected[] = {
{INT_MAX, static_cast<short>(4)},
{3, static_cast<short>(5)},
{2, static_cast<short>(2)},
{1, static_cast<short>(1)}};
{
std::flat_map s(ks, vs, std::greater<int>());

Expand Down Expand Up @@ -278,8 +286,17 @@ void test_initializer_list_compare() {
}

void test_from_range() {
std::list<std::pair<int, short>> r = {{1, 1}, {2, 2}, {1, 1}, {INT_MAX, 4}, {3, 5}};
const std::pair<int, short> expected[] = {{1, 1}, {2, 2}, {3, 5}, {INT_MAX, 4}};
std::list<std::pair<int, short>> r = {
{1, static_cast<short>(1)},
{2, static_cast<short>(2)},
{1, static_cast<short>(1)},
{INT_MAX, static_cast<short>(4)},
{3, static_cast<short>(5)}};
const std::pair<int, short> expected[] = {
{1, static_cast<short>(1)},
{2, static_cast<short>(2)},
{3, static_cast<short>(5)},
{INT_MAX, static_cast<short>(4)}};
{
std::flat_map s(std::from_range, r);
ASSERT_SAME_TYPE(decltype(s), std::flat_map<int, short, std::less<int>>);
Expand All @@ -301,8 +318,17 @@ void test_from_range() {
}

void test_from_range_compare() {
std::list<std::pair<int, short>> r = {{1, 1}, {2, 2}, {1, 1}, {INT_MAX, 4}, {3, 5}};
const std::pair<int, short> expected[] = {{INT_MAX, 4}, {3, 5}, {2, 2}, {1, 1}};
std::list<std::pair<int, short>> r = {
{1, static_cast<short>(1)},
{2, static_cast<short>(2)},
{1, static_cast<short>(1)},
{INT_MAX, static_cast<short>(4)},
{3, static_cast<short>(5)}};
const std::pair<int, short> expected[] = {
{INT_MAX, static_cast<short>(4)},
{3, static_cast<short>(5)},
{2, static_cast<short>(2)},
{1, static_cast<short>(1)}};
{
std::flat_map s(std::from_range, r, std::greater<int>());
ASSERT_SAME_TYPE(decltype(s), std::flat_map<int, short, std::greater<int>>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ void test_containers() {
std::deque<short, test_allocator<short>> vs({1, 2, 1, 4, 5}, test_allocator<int>(0, 43));
std::deque<int, test_allocator<int>> sorted_ks({1, 2, 3, INT_MAX}, test_allocator<int>(0, 42));
std::deque<short, test_allocator<short>> sorted_vs({1, 2, 5, 4}, test_allocator<int>(0, 43));
const std::pair<int, short> expected[] = {{1, 1}, {2, 2}, {3, 5}, {INT_MAX, 4}};
const std::pair<int, short> expected[] = {
{1, static_cast<short>(1)},
{2, static_cast<short>(2)},
{3, static_cast<short>(5)},
{INT_MAX, static_cast<short>(4)}};
{
std::pmr::monotonic_buffer_resource mr;
std::pmr::monotonic_buffer_resource mr2;
Expand Down Expand Up @@ -69,7 +73,11 @@ void test_containers_compare() {
std::deque<short, test_allocator<short>> vs({1, 2, 1, 4, 5}, test_allocator<int>(0, 43));
std::deque<int, test_allocator<int>> sorted_ks({INT_MAX, 3, 2, 1}, test_allocator<int>(0, 42));
std::deque<short, test_allocator<short>> sorted_vs({4, 5, 2, 1}, test_allocator<int>(0, 43));
const std::pair<int, short> expected[] = {{INT_MAX, 4}, {3, 5}, {2, 2}, {1, 1}};
const std::pair<int, short> expected[] = {
{INT_MAX, static_cast<short>(4)},
{3, static_cast<short>(5)},
{2, static_cast<short>(2)},
{1, static_cast<short>(1)}};
{
std::pmr::monotonic_buffer_resource mr;
std::pmr::monotonic_buffer_resource mr2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,42 @@ int main(int, char**) {
!std::is_constructible_v<M, std::initializer_list<std::pair<const int, const short>>, std::allocator<int>>);
}

std::pair<int, short> expected[] = {{1, 1}, {2, 2}, {3, 3}, {5, 2}};
std::pair<int, short> expected[] = {
{1, static_cast<short>(1)}, {2, static_cast<short>(2)}, {3, static_cast<short>(3)}, {5, static_cast<short>(2)}};
{
// flat_map(initializer_list<value_type>);
using M = std::flat_map<int, short>;
std::initializer_list<std::pair<int, short>> il = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
std::initializer_list<std::pair<int, short>> il = {
{5, static_cast<short>(2)},
{2, static_cast<short>(2)},
{2, static_cast<short>(2)},
{3, static_cast<short>(3)},
{1, static_cast<short>(1)},
{3, static_cast<short>(3)}};
M m(il);
assert(std::equal(m.begin(), m.end(), expected, expected + 4));
}
{
// flat_map(initializer_list<value_type>);
// explicit(false)
using M = std::flat_map<int, short>;
M m = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
M m = {{5, static_cast<short>(2)},
{2, static_cast<short>(2)},
{2, static_cast<short>(2)},
{3, static_cast<short>(3)},
{1, static_cast<short>(1)},
{3, static_cast<short>(3)}};
assert(std::equal(m.begin(), m.end(), expected, expected + 4));
}
{
// flat_map(initializer_list<value_type>);
using M = std::flat_map<int, short, std::greater<int>, std::deque<int, min_allocator<int>>>;
M m = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
M m = {{5, static_cast<short>(2)},
{2, static_cast<short>(2)},
{2, static_cast<short>(2)},
{3, static_cast<short>(3)},
{1, static_cast<short>(1)},
{3, static_cast<short>(3)}};
assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
}
{
Expand All @@ -127,20 +144,40 @@ int main(int, char**) {
// flat_map(initializer_list<value_type>, const key_compare&);
using C = test_less<int>;
using M = std::flat_map<int, short, C>;
auto m = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10));
auto m =
M({{5, static_cast<short>(2)},
{2, static_cast<short>(2)},
{2, static_cast<short>(2)},
{3, static_cast<short>(3)},
{1, static_cast<short>(1)},
{3, static_cast<short>(3)}},
C(10));
assert(std::equal(m.begin(), m.end(), expected, expected + 4));
assert(m.key_comp() == C(10));

// explicit(false)
M m2 = {{{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10)};
M m2 = {{{5, static_cast<short>(2)},
{2, static_cast<short>(2)},
{2, static_cast<short>(2)},
{3, static_cast<short>(3)},
{1, static_cast<short>(1)},
{3, static_cast<short>(3)}},
C(10)};
assert(m2 == m);
assert(m2.key_comp() == C(10));
}
{
// flat_map(initializer_list<value_type>, const key_compare&);
// Sorting uses the comparator that was passed in
using M = std::flat_map<int, short, std::function<bool(int, int)>, std::deque<int, min_allocator<int>>>;
auto m = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, std::greater<int>());
auto m =
M({{5, static_cast<short>(2)},
{2, static_cast<short>(2)},
{2, static_cast<short>(2)},
{3, static_cast<short>(3)},
{1, static_cast<short>(1)},
{3, static_cast<short>(3)}},
std::greater<int>());
assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
assert(m.key_comp()(2, 1) == true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,18 @@ int main(int, char**) {
static_assert(!std::is_constructible_v<M3, Iter3, Iter3, const C&, const A2&>);
}

using P = std::pair<int, short>;
P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
P expected[] = {{1, 1}, {2, 4}, {3, 6}};
using P = std::pair<int, short>;
P ar[] = {
{1, static_cast<short>(1)},
{1, static_cast<short>(2)},
{1, static_cast<short>(3)},
{2, static_cast<short>(4)},
{2, static_cast<short>(5)},
{3, static_cast<short>(6)},
{2, static_cast<short>(7)},
{3, static_cast<short>(8)},
{3, static_cast<short>(9)}};
P expected[] = {{1, static_cast<short>(1)}, {2, static_cast<short>(4)}, {3, static_cast<short>(6)}};
{
// flat_map(InputIterator , InputIterator)
// cpp17_input_iterator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ int main(int, char**) {
using A1 = test_allocator<int>;
using A2 = test_allocator<char>;
using M = std::flat_map<int, char, C, std::vector<int, A1>, std::vector<char, A2>>;
M mo = M({{1, 1}, {2, 3}, {3, 2}}, C(5), A1(7));
M mo = M({{1, static_cast<char>(1)}, {2, static_cast<char>(3)}, {3, static_cast<char>(2)}}, C(5), A1(7));
M m = M({}, C(3), A1(7));
m = std::move(mo);
assert((m == M{{1, 1}, {2, 3}, {3, 2}}));
assert((m == M{{1, static_cast<char>(1)}, {2, static_cast<char>(3)}, {3, static_cast<char>(2)}}));
assert(m.key_comp() == C(5));
auto [ks, vs] = std::move(m).extract();
assert(ks.get_allocator() == A1(7));
Expand All @@ -47,10 +47,15 @@ int main(int, char**) {
using A1 = other_allocator<int>;
using A2 = other_allocator<char>;
using M = std::flat_map<int, char, C, std::deque<int, A1>, std::deque<char, A2>>;
M mo = M({{4, 5}, {5, 4}}, C(5), A1(7));
M m = M({{1, 1}, {2, 2}, {3, 3}, {4, 4}}, C(3), A1(7));
M mo = M({{4, static_cast<char>(5)}, {5, static_cast<char>(4)}}, C(5), A1(7));
M m = M({{1, static_cast<char>(1)}, //
{2, static_cast<char>(2)},
{3, static_cast<char>(3)},
{4, static_cast<char>(4)}},
C(3),
A1(7));
m = std::move(mo);
assert((m == M{{4, 5}, {5, 4}}));
assert((m == M{{4, static_cast<char>(5)}, {5, static_cast<char>(4)}}));
assert(m.key_comp() == C(5));
auto [ks, vs] = std::move(m).extract();
assert(ks.get_allocator() == A1(7));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,18 @@ int main(int, char**) {
}
{
// flat_map(InputIterator first, InputIterator last, const Allocator& a);
using P = std::pair<int, short>;
P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
P expected[] = {{1, 1}, {2, 4}, {3, 6}};
using P = std::pair<int, short>;
P ar[] = {
{1, static_cast<short>(1)},
{1, static_cast<short>(2)},
{1, static_cast<short>(3)},
{2, static_cast<short>(4)},
{2, static_cast<short>(5)},
{3, static_cast<short>(6)},
{2, static_cast<short>(7)},
{3, static_cast<short>(8)},
{3, static_cast<short>(9)}};
P expected[] = {{1, static_cast<short>(1)}, {2, static_cast<short>(4)}, {3, static_cast<short>(6)}};
{
// cpp17 iterator
using M = std::flat_map<int, short, std::less<int>, std::pmr::vector<int>, std::pmr::vector<short>>;
Expand Down Expand Up @@ -242,9 +251,18 @@ int main(int, char**) {
}
{
// flat_map(from_range_t, R&&, const Alloc&);
using P = std::pair<int, short>;
P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
P expected[] = {{1, 1}, {2, 4}, {3, 6}};
using P = std::pair<int, short>;
P ar[] = {
{1, static_cast<short>(1)},
{1, static_cast<short>(2)},
{1, static_cast<short>(3)},
{2, static_cast<short>(4)},
{2, static_cast<short>(5)},
{3, static_cast<short>(6)},
{2, static_cast<short>(7)},
{3, static_cast<short>(8)},
{3, static_cast<short>(9)}};
P expected[] = {{1, static_cast<short>(1)}, {2, static_cast<short>(4)}, {3, static_cast<short>(6)}};
{
// input_range
using M = std::flat_map<int, short, std::less<int>, std::pmr::vector<int>, std::pmr::vector<short>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,18 @@ int main(int, char**) {
static_assert(!std::is_constructible_v<M, std::from_range_t, std::vector<NonPairLike>&, const C&, const A1&>);
}

using P = std::pair<int, short>;
P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
P expected[] = {{1, 1}, {2, 4}, {3, 6}};
using P = std::pair<int, short>;
P ar[] = {
{1, static_cast<short>(1)},
{1, static_cast<short>(2)},
{1, static_cast<short>(3)},
{2, static_cast<short>(4)},
{2, static_cast<short>(5)},
{3, static_cast<short>(6)},
{2, static_cast<short>(7)},
{3, static_cast<short>(8)},
{3, static_cast<short>(9)}};
P expected[] = {{1, static_cast<short>(1)}, {2, static_cast<short>(4)}, {3, static_cast<short>(6)}};
{
// flat_map(from_range_t, R&&)
// input_range && !common
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,17 @@ int main(int, char**) {
auto vs2 = vs;

auto m = M(std::sorted_unique, ks, vs);
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert((m == M{{1, static_cast<char>(4)},
{2, static_cast<char>(3)},
{4, static_cast<char>(2)},
{10, static_cast<char>(1)}}));
m = M(std::sorted_unique, std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert((m == M{{1, static_cast<char>(4)},
{2, static_cast<char>(3)},
{4, static_cast<char>(2)},
{10, static_cast<char>(1)}}));

// explicit(false)
M m2 = {std::sorted_unique, std::move(ks2), std::move(vs2)};
Expand All @@ -85,11 +91,17 @@ int main(int, char**) {
Ks ks = {10, 4, 2, 1};
Vs vs = {1, 2, 3, 4};
auto m = M(std::sorted_unique, ks, vs);
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert((m == M{{1, static_cast<char>(4)},
{2, static_cast<char>(3)},
{4, static_cast<char>(2)},
{10, static_cast<char>(1)}}));
m = M(std::sorted_unique, std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert((m == M{{1, static_cast<char>(4)},
{2, static_cast<char>(3)},
{4, static_cast<char>(2)},
{10, static_cast<char>(1)}}));
}
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type)
Expand All @@ -113,7 +125,10 @@ int main(int, char**) {
std::vector<char> vs = {4, 3, 2, 1};

auto m = M(std::sorted_unique, ks, vs, C(4));
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert((m == M{{1, static_cast<char>(4)},
{2, static_cast<char>(3)},
{4, static_cast<char>(2)},
{10, static_cast<char>(1)}}));
assert(m.key_comp() == C(4));

// explicit(false)
Expand Down
Loading