Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
54e205f
Drop `using namespace ranges;`, qualify `ranges::input_range` and `ra…
StephanTLavavej Jan 26, 2026
5ad5748
Drop `std::` for `less`, `greater`, `move`, `copy`.
StephanTLavavej Jan 26, 2026
180e078
Use `ranges::equal` and `println()`.
StephanTLavavej Jan 26, 2026
1397a42
`INT_MAX` => `(numeric_limits<int>::max)()`
StephanTLavavej Jan 26, 2026
aa59836
Cite N5032 [associative.reqmts.general] instead of P2077R3 Heterogene…
StephanTLavavej Jan 26, 2026
cab2c03
Drop extra newlines.
StephanTLavavej Jan 26, 2026
2b63675
Run tests in definition order.
StephanTLavavej Jan 26, 2026
283b596
Overhaul `test_constructors()` to actually test all normal constructors.
StephanTLavavej Jan 26, 2026
f0eb53a
Test construction from just an allocator.
StephanTLavavej Jan 26, 2026
8a6ca17
Expand `test_insert_2()`, fixing "TRANSITION, too simple".
StephanTLavavej Jan 27, 2026
ca727a3
Extract identical key_comparer to test_container_requirements.hpp.
StephanTLavavej Jan 27, 2026
70d7b39
`key_comparer::extract_key()` can be private and static.
StephanTLavavej Jan 27, 2026
ac56e1d
comparer => comparator
StephanTLavavej Jan 27, 2026
a236a74
Pre-existing/unrelated: comparer => comparator
StephanTLavavej Jan 27, 2026
b17114f
Prefer range-for with `auto&` / `const auto&`.
StephanTLavavej Jan 27, 2026
4fa9c4e
Reduce `dist_seq`'s scope to avoid confusion with `dist_idx`.
StephanTLavavej Jan 27, 2026
1bfdf81
Extract the engine, prefer `mt19937_64`.
StephanTLavavej Jan 27, 2026
ff9dd75
Avoid almost always auto.
StephanTLavavej Jan 27, 2026
d80d7b8
Improve comments.
StephanTLavavej Jan 27, 2026
e6bedf7
Add const.
StephanTLavavej Jan 27, 2026
a8161a8
Improve `namespace test_erase_compile_time`.
StephanTLavavej Jan 27, 2026
81c68c0
Be more specific about find() results.
StephanTLavavej Jan 27, 2026
2a8e67c
Test const overloads of transparent operations.
StephanTLavavej Jan 27, 2026
df26826
De-templatize the "duplicates" tests, they're always exercising the u…
StephanTLavavej Jan 27, 2026
0d2b66c
Add test coverage: iterators, capacity, replace(), clear(), equality,…
StephanTLavavej Jan 27, 2026
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
18 changes: 18 additions & 0 deletions tests/std/include/test_container_requirements.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,21 @@ void assert_three_way_comparability() {
static_assert(std::three_way_comparable<T>);
}
}

class key_comparator {
private:
static const auto& extract_key(const auto& obj) {
if constexpr (requires { obj.key; }) {
return obj.key;
} else {
return obj;
}
}

public:
bool operator()(const auto& lhs, const auto& rhs) const {
return extract_key(lhs) < extract_key(rhs);
}

using is_transparent = int;
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// A brief overview of the contents of this file:
//
// The first 650 lines or so of this file (everything up to the first use of DEFINE_TEST) are test
// utilities: stub allocators, comparers, and other kinds of types with which we can instantiate
// utilities: stub allocators, comparators, and other kinds of types with which we can instantiate
// containers; test types that define a restricted set of operations; and a set of container traits
// classes that unify the interfaces for the containers so we can use a common set of tests for
// them (these traits also define a few useful properties for each container so we know what to
Expand Down Expand Up @@ -1678,7 +1678,7 @@ NOT_SUPPORTED_SPECIALIZATION(test_ordered_associative_typedefs_for_maps, tag_mul
NOT_SUPPORTED_SPECIALIZATION(test_ordered_associative_typedefs_for_maps, tag_set);


DEFINE_TEST(test_ordered_associative_default_constructor_with_comparer,
DEFINE_TEST(test_ordered_associative_default_constructor_with_comparator,
{
// X(c) and X a(c);
// Requires: key_compare is CopyConstructible
Expand Down Expand Up @@ -1710,13 +1710,13 @@ DEFINE_TEST(test_ordered_associative_default_constructor_with_comparer,
});


DEFINE_TEST(test_ordered_associative_range_constructor_with_comparer, {
DEFINE_TEST(test_ordered_associative_range_constructor_with_comparator, {
// SPEC: These are the only two operations for which traits are specified for key_compare, but
// there are many other operations for which key_compare must meet other requirements (e.g. a
// call to a.key_comp() necessitates that the key_comp type is move constructible.
//
// In the rest of the tests, I have assumed std::less for the comparer, which meets any possible
// requirements, but it should be considered whether the comparer requirements should be more
// In the rest of the tests, I have assumed std::less for the comparator, which meets any possible
// requirements, but it should be considered whether the comparator requirements should be more
// thoroughly specified.

std::move_iterator<input_iterator<typename Traits::emplace_argument_type>> i;
Expand Down Expand Up @@ -1746,7 +1746,7 @@ DEFINE_TEST(test_ordered_associative_initializer_list_assign, {
});


DEFINE_TEST(test_ordered_associative_comparers, {
DEFINE_TEST(test_ordered_associative_comparators, {
// a.key_comp()
// [No Requires clause]
c_of_erasable const a;
Expand Down Expand Up @@ -1926,10 +1926,10 @@ struct check_all_ordered_associative_requirements {
check_all_ordered_associative_requirements() {
test_ordered_associative_typedefs<Tag>();
test_ordered_associative_typedefs_for_maps<Tag>();
test_ordered_associative_default_constructor_with_comparer<Tag>();
test_ordered_associative_range_constructor_with_comparer<Tag>();
test_ordered_associative_default_constructor_with_comparator<Tag>();
test_ordered_associative_range_constructor_with_comparator<Tag>();
test_ordered_associative_initializer_list_assign<Tag>();
test_ordered_associative_comparers<Tag>();
test_ordered_associative_comparators<Tag>();
test_ordered_associative_emplace<Tag>();
test_ordered_associative_insert<Tag>();
test_ordered_associative_erase<Tag>();
Expand Down
81 changes: 26 additions & 55 deletions tests/std/tests/P0429R9_flat_map/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,22 +233,6 @@ struct MyAllocatorCounter {
size_t activeAllocations;
};

struct key_comparer {
const auto& extract_key(const auto& obj) const {
if constexpr (requires { obj.key; }) {
return obj.key;
} else {
return obj;
}
}

bool operator()(const auto& lhs, const auto& rhs) const {
return extract_key(lhs) < extract_key(rhs);
}

using is_transparent = int;
};

template <template <class...> class KeyCont, template <class...> class MappedCont>
void test_construction() {
// Using CTAD, the given MyAllocator is only used by the container when the constructor (deduction guide)
Expand Down Expand Up @@ -1188,7 +1172,7 @@ void test_map_operations_transparent() {
}
};

Map<int, char, key_comparer> fm{{0, 'a'}, {3, 'g'}, {5, 't'}};
Map<int, char, key_comparator> fm{{0, 'a'}, {3, 'g'}, {5, 't'}};
assert(check_key_content(fm, {0, 3, 5}));
assert(check_value_content(fm, {'a', 'g', 't'}));

Expand Down Expand Up @@ -1511,61 +1495,48 @@ void test_death_insert_unsorted_initializer_list() {
cont.insert(sorted, {{137, 'a'}, {42, 'g'}, {3337, 'f'}, {15, 'r'}});
}

template <cont_type type>
void test_death_construct_duplicates_initializer_list() {
using C = conditional_t<type == cont_type::unique, flat_map<int, char>, flat_multimap<int, char>>;
const conditional_t<type == cont_type::unique, sorted_unique_t, sorted_equivalent_t> sorted;
C cont(sorted, {{42, 'a'}, {137, 'g'}, {137, 'f'}, {3337, 'r'}});
using C = flat_map<int, char>;
C cont(sorted_unique, {{42, 'a'}, {137, 'g'}, {137, 'f'}, {3337, 'r'}});
}

template <cont_type type>
void test_death_construct_duplicates_iter_iter() {
using C = conditional_t<type == cont_type::unique, flat_map<int, char>, flat_multimap<int, char>>;
const conditional_t<type == cont_type::unique, sorted_unique_t, sorted_equivalent_t> sorted;
vector<typename C::value_type> values{{42, 'a'}, {137, 'g'}, {137, 'f'}, {3337, 'r'}};
C cont(sorted, values.begin(), values.end());
using C = flat_map<int, char>;
vector<C::value_type> values{{42, 'a'}, {137, 'g'}, {137, 'f'}, {3337, 'r'}};
C cont(sorted_unique, values.begin(), values.end());
}

template <cont_type type>
void test_death_construct_duplicates_container() {
using C = conditional_t<type == cont_type::unique, flat_map<int, char>, flat_multimap<int, char>>;
const conditional_t<type == cont_type::unique, sorted_unique_t, sorted_equivalent_t> sorted;
typename C::key_container_type keys{42, 137, 137, 3337};
typename C::mapped_container_type mapped{'a', 'g', 'f', 'r'};
C cont(sorted, keys, mapped);
using C = flat_map<int, char>;
C::key_container_type keys{42, 137, 137, 3337};
C::mapped_container_type mapped{'a', 'g', 'f', 'r'};
C cont(sorted_unique, keys, mapped);
}

template <cont_type type>
void test_death_replace_duplicates_container() {
using C = conditional_t<type == cont_type::unique, flat_map<int, char>, flat_multimap<int, char>>;
using C = flat_map<int, char>;
C cont;
cont.replace({42, 137, 137, 3337}, {'a', 'g', 'f', 'r'});
}

template <cont_type type>
void test_death_insert_duplicates_iter_iter() {
using C = conditional_t<type == cont_type::unique, flat_map<int, char>, flat_multimap<int, char>>;
const conditional_t<type == cont_type::unique, sorted_unique_t, sorted_equivalent_t> sorted;
vector<typename C::value_type> values{{42, 'a'}, {137, 'g'}, {137, 'f'}, {3337, 'r'}};
using C = flat_map<int, char>;
vector<C::value_type> values{{42, 'a'}, {137, 'g'}, {137, 'f'}, {3337, 'r'}};
C cont;
cont.insert(sorted, values.begin(), values.end());
cont.insert(sorted_unique, values.begin(), values.end());
}

template <cont_type type>
void test_death_insert_duplicates_range() {
using C = conditional_t<type == cont_type::unique, flat_map<int, char>, flat_multimap<int, char>>;
const conditional_t<type == cont_type::unique, sorted_unique_t, sorted_equivalent_t> sorted;
vector<typename C::value_type> values{{42, 'a'}, {137, 'g'}, {137, 'f'}, {3337, 'r'}};
using C = flat_map<int, char>;
vector<C::value_type> values{{42, 'a'}, {137, 'g'}, {137, 'f'}, {3337, 'r'}};
C cont;
cont.insert_range(sorted, values);
cont.insert_range(sorted_unique, values);
}

template <cont_type type>
void test_death_insert_duplicates_initializer_list() {
using C = conditional_t<type == cont_type::unique, flat_map<int, char>, flat_multimap<int, char>>;
const conditional_t<type == cont_type::unique, sorted_unique_t, sorted_equivalent_t> sorted;
using C = flat_map<int, char>;
C cont;
cont.insert(sorted, {{42, 'a'}, {137, 'g'}, {137, 'f'}, {3337, 'r'}});
cont.insert(sorted_unique, {{42, 'a'}, {137, 'g'}, {137, 'f'}, {3337, 'r'}});
}

template <cont_type type>
Expand Down Expand Up @@ -1640,13 +1611,13 @@ int main(int argc, char* argv[]) {
test_death_insert_unsorted_initializer_list<cont_type::multi>,

// Tests shared between flat_set and flat_map - violation of unique elements
test_death_construct_duplicates_initializer_list<cont_type::unique>,
test_death_construct_duplicates_iter_iter<cont_type::unique>,
test_death_construct_duplicates_container<cont_type::unique>,
test_death_replace_duplicates_container<cont_type::unique>,
test_death_insert_duplicates_iter_iter<cont_type::unique>,
test_death_insert_duplicates_range<cont_type::unique>,
test_death_insert_duplicates_initializer_list<cont_type::unique>,
test_death_construct_duplicates_initializer_list,
test_death_construct_duplicates_iter_iter,
test_death_construct_duplicates_container,
test_death_replace_duplicates_container,
test_death_insert_duplicates_iter_iter,
test_death_insert_duplicates_range,
test_death_insert_duplicates_initializer_list,

// Tests not present in flat_set - mismatch of length of key and mapped containers
test_death_different_size_ctor<cont_type::unique>,
Expand Down
Loading