[libcxx-commits] [libcxx] [libc++] constexpr flat_multimap (PR #148417)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 15 10:06:36 PDT 2025
================
@@ -31,89 +33,68 @@
#include "test_allocator.h"
#include "test_iterators.h"
#include "test_macros.h"
+#include "../helpers.h"
#include "../../../test_compare.h"
-int main(int, char**) {
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test() {
{
- // The constructors in this subclause shall not participate in overload
- // resolution unless uses_allocator_v<key_container_type, Alloc> is true
- // and uses_allocator_v<mapped_container_type, Alloc> is true.
-
- using C = test_less<int>;
- using A1 = test_allocator<int>;
- using A2 = other_allocator<int>;
- using V1 = std::vector<int, A1>;
- using V2 = std::vector<int, A2>;
- using M1 = std::flat_multimap<int, int, C, V1, V1>;
- using M2 = std::flat_multimap<int, int, C, V1, V2>;
- using M3 = std::flat_multimap<int, int, C, V2, V1>;
- static_assert(std::is_constructible_v<M1, std::sorted_equivalent_t, const V1&, const V1&, const A1&>);
- static_assert(!std::is_constructible_v<M1, std::sorted_equivalent_t, const V1&, const V1&, const A2&>);
- static_assert(!std::is_constructible_v<M2, std::sorted_equivalent_t, const V1&, const V2&, const A2&>);
- static_assert(!std::is_constructible_v<M3, std::sorted_equivalent_t, const V2&, const V1&, const A2&>);
-
- static_assert(std::is_constructible_v<M1, std::sorted_equivalent_t, const V1&, const V1&, const C&, const A1&>);
- static_assert(!std::is_constructible_v<M1, std::sorted_equivalent_t, const V1&, const V1&, const C&, const A2&>);
- static_assert(!std::is_constructible_v<M2, std::sorted_equivalent_t, const V1&, const V2&, const C&, const A2&>);
- static_assert(!std::is_constructible_v<M3, std::sorted_equivalent_t, const V2&, const V1&, const C&, const A2&>);
- }
- {
- // flat_multimap(sorted_equivalent_t, key_container_type , mapped_container_type)
- using M = std::flat_multimap<int, char>;
- std::vector<int> ks = {1, 4, 4, 10};
- std::vector<char> vs = {4, 3, 2, 1};
- auto ks2 = ks;
- auto vs2 = vs;
+ // flat_multimap(sorted_unique_t, key_container_type , mapped_container_type)
+ using M = std::flat_multimap<int, char, std::less<int>, KeyContainer<int>, ValueContainer<char>>;
+ KeyContainer<int> ks = {1, 4, 4, 10};
+ ValueContainer<char> vs = {4, 3, 2, 1};
+ auto ks2 = ks;
+ auto vs2 = vs;
auto m = M(std::sorted_equivalent, ks, vs);
- assert((m == M{{1, 4}, {4, 3}, {4, 2}, {10, 1}}));
+ assert(std::ranges::equal(m, std::vector<std::pair<int, char>>{{1, 4}, {4, 3}, {4, 2}, {10, 1}}));
m = M(std::sorted_equivalent, 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}, {4, 3}, {4, 2}, {10, 1}}));
+ assert(std::ranges::equal(m, std::vector<std::pair<int, char>>{{1, 4}, {4, 3}, {4, 2}, {10, 1}}));
// explicit(false)
M m2 = {std::sorted_equivalent, std::move(ks2), std::move(vs2)};
assert(m == m2);
}
{
- // flat_multimap(sorted_equivalent_t, key_container_type , mapped_container_type)
+ // flat_multimap(sorted_unique_t, key_container_type , mapped_container_type)
// non-default container, comparator and allocator type
- using Ks = std::deque<int, min_allocator<int>>;
- using Vs = std::deque<char, min_allocator<char>>;
+ using Ks = KeyContainer<int, min_allocator<int>>;
+ using Vs = ValueContainer<char, min_allocator<char>>;
using M = std::flat_multimap<int, char, std::greater<int>, Ks, Vs>;
- Ks ks = {10, 1, 1, 1};
+ Ks ks = {10, 4, 4, 1};
Vs vs = {1, 2, 3, 4};
auto m = M(std::sorted_equivalent, ks, vs);
- assert((m == M{{1, 2}, {1, 3}, {1, 4}, {10, 1}}));
+ assert(std::ranges::equal(m, std::vector<std::pair<int, char>>{{10, 1}, {4, 2}, {4, 3}, {1, 4}}));
m = M(std::sorted_equivalent, std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
- assert((m == M{{1, 2}, {1, 3}, {1, 4}, {10, 1}}));
+ assert(std::ranges::equal(m, std::vector<std::pair<int, char>>{{10, 1}, {4, 2}, {4, 3}, {1, 4}}));
}
{
- // flat_multimap(sorted_equivalent_t, key_container_type , mapped_container_type)
+ // flat_multimap(sorted_unique_t, key_container_type , mapped_container_type)
// allocator copied into the containers
using A = test_allocator<int>;
- using M = std::flat_multimap<int, int, std::less<int>, std::vector<int, A>, std::deque<int, A>>;
- auto ks = std::vector<int, A>({2, 2, 4, 10}, A(4));
- auto vs = std::deque<int, A>({4, 3, 2, 1}, A(5));
+ using M = std::flat_multimap<int, int, std::less<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
+ auto ks = KeyContainer<int, A>({1, 4, 4, 10}, A(4));
+ auto vs = ValueContainer<int, A>({4, 3, 2, 1}, A(5));
auto m = M(std::sorted_equivalent, std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
- assert((m == M{{2, 4}, {2, 3}, {4, 2}, {10, 1}}));
+ assert(std::ranges::equal(m, std::vector<std::pair<int, char>>{{1, 4}, {4, 3}, {4, 2}, {10, 1}}));
assert(m.keys().get_allocator() == A(4));
assert(m.values().get_allocator() == A(5));
}
{
- // flat_multimap(sorted_equivalent_t, key_container_type , mapped_container_type, key_compare)
- using C = test_less<int>;
- using M = std::flat_multimap<int, char, C>;
- std::vector<int> ks = {1, 2, 10, 10};
- std::vector<char> vs = {4, 3, 2, 1};
+ // flat_multimap(sorted_unique_t, key_container_type , mapped_container_type, key_compare)
----------------
ldionne wrote:
Similar comment here.
https://github.com/llvm/llvm-project/pull/148417
More information about the libcxx-commits
mailing list