[libcxx-commits] [libcxx] [libc++] constexpr flat_map (PR #137453)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Apr 26 11:48:51 PDT 2025
https://github.com/huixie90 updated https://github.com/llvm/llvm-project/pull/137453
>From 360224cf3b9b19013bda4cc2aaad49c840dcd3e9 Mon Sep 17 00:00:00 2001
From: Hui Xie <hui.xie1990 at gmail.com>
Date: Sat, 26 Apr 2025 11:05:21 +0100
Subject: [PATCH 1/5] [libc++] constexpr flat_map
---
libcxx/include/__flat_map/flat_map.h | 391 +++++++++++-------
.../include/__flat_map/key_value_iterator.h | 58 ++-
libcxx/include/__flat_map/utils.h | 4 +-
libcxx/test/std/containers/Emplaceable.h | 16 +-
.../flat.map/flat.map.access/at.pass.cpp | 41 +-
.../flat.map.access/at_transparent.pass.cpp | 40 +-
.../flat.map.access/index_key.pass.cpp | 25 +-
.../flat.map.access/index_rv_key.pass.cpp | 23 +-
.../index_transparent.pass.cpp | 25 +-
.../flat.map/flat.map.capacity/empty.pass.cpp | 22 +-
.../flat.map.capacity/max_size.pass.cpp | 12 +-
.../flat.map/flat.map.capacity/size.pass.cpp | 23 +-
.../flat.map/flat.map.cons/alloc.pass.cpp | 46 ++-
.../assign_initializer_list.pass.cpp | 22 +-
.../flat.map/flat.map.cons/compare.pass.cpp | 108 +++--
.../flat.map.cons/containers.pass.cpp | 153 ++++---
.../flat.map/flat.map.cons/copy.pass.cpp | 32 +-
.../flat.map.cons/copy_alloc.pass.cpp | 58 ++-
.../flat.map.cons/copy_assign.pass.cpp | 35 +-
.../flat.map/flat.map.cons/default.pass.cpp | 40 +-
.../flat.map.cons/default_noexcept.pass.cpp | 16 +-
.../flat.map.cons/dtor_noexcept.pass.cpp | 41 +-
.../flat.map.cons/initializer_list.pass.cpp | 159 +++----
.../flat.map/flat.map.cons/iter_iter.pass.cpp | 189 ++++++---
.../flat.map/flat.map.cons/move.pass.cpp | 35 +-
.../flat.map.cons/move_alloc.pass.cpp | 64 ++-
.../flat.map.cons/move_assign.pass.cpp | 31 +-
.../flat.map.cons/move_assign_clears.pass.cpp | 43 +-
... => move_assign_noexcept.compile.pass.cpp} | 4 +-
.../flat.map/flat.map.cons/range.pass.cpp | 241 +++++++----
.../flat.map.cons/sorted_container.pass.cpp | 118 +++---
.../sorted_initializer_list.pass.cpp | 164 ++++----
.../flat.map.cons/sorted_iter_iter.pass.cpp | 127 ++++--
.../flat.map.erasure/erase_if.pass.cpp | 28 +-
.../flat.map.iterators/iterator.pass.cpp | 20 +-
.../iterator_comparison.pass.cpp | 20 +-
.../reverse_iterator.pass.cpp | 100 +++--
.../flat.map.modifiers/clear.pass.cpp | 20 +-
.../flat.map.modifiers/emplace.pass.cpp | 26 +-
.../flat.map.modifiers/emplace_hint.pass.cpp | 27 +-
.../flat.map.modifiers/erase_iter.pass.cpp | 23 +-
.../erase_iter_iter.pass.cpp | 24 +-
.../flat.map.modifiers/erase_key.pass.cpp | 23 +-
.../erase_key_transparent.pass.cpp | 33 +-
.../flat.map.modifiers/extract.pass.cpp | 23 +-
.../flat.map.modifiers/insert_cv.pass.cpp | 23 +-
.../insert_initializer_list.pass.cpp | 39 +-
.../insert_iter_cv.pass.cpp | 23 +-
.../insert_iter_iter.pass.cpp | 50 ++-
.../insert_iter_rv.pass.cpp | 26 +-
.../insert_or_assign.pass.cpp | 24 +-
.../insert_or_assign_transparent.pass.cpp | 52 ++-
.../flat.map.modifiers/insert_range.pass.cpp | 27 +-
.../flat.map.modifiers/insert_rv.pass.cpp | 24 +-
.../insert_sorted_initializer_list.pass.cpp | 39 +-
.../insert_sorted_iter_iter.pass.cpp | 22 +-
.../insert_transparent.pass.cpp | 159 +++----
.../flat.map.modifiers/replace.pass.cpp | 23 +-
.../flat.map.modifiers/swap_free.pass.cpp | 20 +-
.../flat.map.modifiers/swap_member.pass.cpp | 20 +-
.../flat.map.modifiers/try_emplace.pass.cpp | 94 +++--
.../try_emplace_transparent.pass.cpp | 54 ++-
.../flat.map/flat.map.observers/comp.pass.cpp | 17 +-
.../flat.map.observers/keys_values.pass.cpp | 20 +-
.../flat.map.operations/contains.pass.cpp | 20 +-
.../contains_transparent.pass.cpp | 21 +-
.../flat.map.operations/count.pass.cpp | 20 +-
.../count_transparent.pass.cpp | 20 +-
.../flat.map.operations/equal_range.pass.cpp | 20 +-
.../equal_range_transparent.pass.cpp | 20 +-
.../flat.map.operations/find.pass.cpp | 20 +-
.../find_transparent.pass.cpp | 20 +-
.../flat.map.operations/lower_bound.pass.cpp | 20 +-
.../lower_bound_transparent.pass.cpp | 20 +-
.../flat.map.operations/upper_bound.pass.cpp | 20 +-
.../upper_bound_transparent.pass.cpp | 20 +-
.../container.adaptors/flat.map/helpers.h | 11 +-
.../flat.map/incomplete_type.pass.cpp | 17 +-
.../flat.map/op_compare.pass.cpp | 23 +-
.../container.adaptors/flat_helpers.h | 37 +-
libcxx/test/std/containers/test_compare.h | 18 +-
libcxx/test/support/MinSequenceContainer.h | 41 +-
82 files changed, 2695 insertions(+), 1222 deletions(-)
rename libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/{move_assign_noexcept.pass.cpp => move_assign_noexcept.compile.pass.cpp} (99%)
diff --git a/libcxx/include/__flat_map/flat_map.h b/libcxx/include/__flat_map/flat_map.h
index f5abfd0985280..452938595b7d4 100644
--- a/libcxx/include/__flat_map/flat_map.h
+++ b/libcxx/include/__flat_map/flat_map.h
@@ -115,11 +115,12 @@ class flat_map {
class value_compare {
private:
key_compare __comp_;
- _LIBCPP_HIDE_FROM_ABI value_compare(key_compare __c) : __comp_(__c) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 value_compare(key_compare __c) : __comp_(__c) {}
friend flat_map;
public:
- _LIBCPP_HIDE_FROM_ABI bool operator()(const_reference __x, const_reference __y) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool
+ operator()(const_reference __x, const_reference __y) const {
return __comp_(__x.first, __y.first);
}
};
@@ -138,14 +139,14 @@ class flat_map {
public:
// [flat.map.cons], construct/copy/destroy
- _LIBCPP_HIDE_FROM_ABI flat_map() noexcept(
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map() noexcept(
is_nothrow_default_constructible_v<_KeyContainer> && is_nothrow_default_constructible_v<_MappedContainer> &&
is_nothrow_default_constructible_v<_Compare>)
: __containers_(), __compare_() {}
_LIBCPP_HIDE_FROM_ABI flat_map(const flat_map&) = default;
- _LIBCPP_HIDE_FROM_ABI flat_map(flat_map&& __other) noexcept(
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(flat_map&& __other) noexcept(
is_nothrow_move_constructible_v<_KeyContainer> && is_nothrow_move_constructible_v<_MappedContainer> &&
is_nothrow_move_constructible_v<_Compare>)
# if _LIBCPP_HAS_EXCEPTIONS
@@ -166,7 +167,7 @@ class flat_map {
template <class _Allocator>
requires __allocator_ctor_constraint<_Allocator>
- _LIBCPP_HIDE_FROM_ABI flat_map(const flat_map& __other, const _Allocator& __alloc)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(const flat_map& __other, const _Allocator& __alloc)
: flat_map(__ctor_uses_allocator_tag{},
__alloc,
__other.__containers_.keys,
@@ -175,7 +176,7 @@ class flat_map {
template <class _Allocator>
requires __allocator_ctor_constraint<_Allocator>
- _LIBCPP_HIDE_FROM_ABI flat_map(flat_map&& __other, const _Allocator& __alloc)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(flat_map&& __other, const _Allocator& __alloc)
# if _LIBCPP_HAS_EXCEPTIONS
try
# endif // _LIBCPP_HAS_EXCEPTIONS
@@ -192,7 +193,7 @@ class flat_map {
# endif // _LIBCPP_HAS_EXCEPTIONS
}
- _LIBCPP_HIDE_FROM_ABI flat_map(
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(
key_container_type __key_cont, mapped_container_type __mapped_cont, const key_compare& __comp = key_compare())
: __containers_{.keys = std::move(__key_cont), .values = std::move(__mapped_cont)}, __compare_(__comp) {
_LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
@@ -202,7 +203,7 @@ class flat_map {
template <class _Allocator>
requires __allocator_ctor_constraint<_Allocator>
- _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
flat_map(const key_container_type& __key_cont, const mapped_container_type& __mapped_cont, const _Allocator& __alloc)
: flat_map(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont) {
_LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
@@ -212,7 +213,7 @@ class flat_map {
template <class _Allocator>
requires __allocator_ctor_constraint<_Allocator>
- _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
flat_map(const key_container_type& __key_cont,
const mapped_container_type& __mapped_cont,
const key_compare& __comp,
@@ -223,7 +224,7 @@ class flat_map {
__sort_and_unique();
}
- _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
flat_map(sorted_unique_t,
key_container_type __key_cont,
mapped_container_type __mapped_cont,
@@ -237,7 +238,7 @@ class flat_map {
template <class _Allocator>
requires __allocator_ctor_constraint<_Allocator>
- _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
flat_map(sorted_unique_t,
const key_container_type& __key_cont,
const mapped_container_type& __mapped_cont,
@@ -251,12 +252,12 @@ class flat_map {
template <class _Allocator>
requires __allocator_ctor_constraint<_Allocator>
- _LIBCPP_HIDE_FROM_ABI
- flat_map(sorted_unique_t,
- const key_container_type& __key_cont,
- const mapped_container_type& __mapped_cont,
- const key_compare& __comp,
- const _Allocator& __alloc)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(
+ sorted_unique_t,
+ const key_container_type& __key_cont,
+ const mapped_container_type& __mapped_cont,
+ const key_compare& __comp,
+ const _Allocator& __alloc)
: flat_map(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont, __comp) {
_LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(),
"flat_map keys and mapped containers have different size");
@@ -264,21 +265,22 @@ class flat_map {
__is_sorted_and_unique(__containers_.keys), "Either the key container is not sorted or it contains duplicates");
}
- _LIBCPP_HIDE_FROM_ABI explicit flat_map(const key_compare& __comp) : __containers_(), __compare_(__comp) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit flat_map(const key_compare& __comp)
+ : __containers_(), __compare_(__comp) {}
template <class _Allocator>
requires __allocator_ctor_constraint<_Allocator>
- _LIBCPP_HIDE_FROM_ABI flat_map(const key_compare& __comp, const _Allocator& __alloc)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(const key_compare& __comp, const _Allocator& __alloc)
: flat_map(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {}
template <class _Allocator>
requires __allocator_ctor_constraint<_Allocator>
- _LIBCPP_HIDE_FROM_ABI explicit flat_map(const _Allocator& __alloc)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit flat_map(const _Allocator& __alloc)
: flat_map(__ctor_uses_allocator_empty_tag{}, __alloc) {}
template <class _InputIterator>
requires __has_input_iterator_category<_InputIterator>::value
- _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
flat_map(_InputIterator __first, _InputIterator __last, const key_compare& __comp = key_compare())
: __containers_(), __compare_(__comp) {
insert(__first, __last);
@@ -286,7 +288,7 @@ class flat_map {
template <class _InputIterator, class _Allocator>
requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>)
- _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
flat_map(_InputIterator __first, _InputIterator __last, const key_compare& __comp, const _Allocator& __alloc)
: flat_map(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {
insert(__first, __last);
@@ -294,99 +296,105 @@ class flat_map {
template <class _InputIterator, class _Allocator>
requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>)
- _LIBCPP_HIDE_FROM_ABI flat_map(_InputIterator __first, _InputIterator __last, const _Allocator& __alloc)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
+ flat_map(_InputIterator __first, _InputIterator __last, const _Allocator& __alloc)
: flat_map(__ctor_uses_allocator_empty_tag{}, __alloc) {
insert(__first, __last);
}
template <_ContainerCompatibleRange<value_type> _Range>
- _LIBCPP_HIDE_FROM_ABI flat_map(from_range_t __fr, _Range&& __rg)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(from_range_t __fr, _Range&& __rg)
: flat_map(__fr, std::forward<_Range>(__rg), key_compare()) {}
template <_ContainerCompatibleRange<value_type> _Range, class _Allocator>
requires __allocator_ctor_constraint<_Allocator>
- _LIBCPP_HIDE_FROM_ABI flat_map(from_range_t, _Range&& __rg, const _Allocator& __alloc)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(from_range_t, _Range&& __rg, const _Allocator& __alloc)
: flat_map(__ctor_uses_allocator_empty_tag{}, __alloc) {
insert_range(std::forward<_Range>(__rg));
}
template <_ContainerCompatibleRange<value_type> _Range>
- _LIBCPP_HIDE_FROM_ABI flat_map(from_range_t, _Range&& __rg, const key_compare& __comp) : flat_map(__comp) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(from_range_t, _Range&& __rg, const key_compare& __comp)
+ : flat_map(__comp) {
insert_range(std::forward<_Range>(__rg));
}
template <_ContainerCompatibleRange<value_type> _Range, class _Allocator>
requires __allocator_ctor_constraint<_Allocator>
- _LIBCPP_HIDE_FROM_ABI flat_map(from_range_t, _Range&& __rg, const key_compare& __comp, const _Allocator& __alloc)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
+ flat_map(from_range_t, _Range&& __rg, const key_compare& __comp, const _Allocator& __alloc)
: flat_map(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {
insert_range(std::forward<_Range>(__rg));
}
template <class _InputIterator>
requires __has_input_iterator_category<_InputIterator>::value
- _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
flat_map(sorted_unique_t, _InputIterator __first, _InputIterator __last, const key_compare& __comp = key_compare())
: __containers_(), __compare_(__comp) {
insert(sorted_unique, __first, __last);
}
template <class _InputIterator, class _Allocator>
requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>)
- _LIBCPP_HIDE_FROM_ABI
- flat_map(sorted_unique_t,
- _InputIterator __first,
- _InputIterator __last,
- const key_compare& __comp,
- const _Allocator& __alloc)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(
+ sorted_unique_t,
+ _InputIterator __first,
+ _InputIterator __last,
+ const key_compare& __comp,
+ const _Allocator& __alloc)
: flat_map(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {
insert(sorted_unique, __first, __last);
}
template <class _InputIterator, class _Allocator>
requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>)
- _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
flat_map(sorted_unique_t, _InputIterator __first, _InputIterator __last, const _Allocator& __alloc)
: flat_map(__ctor_uses_allocator_empty_tag{}, __alloc) {
insert(sorted_unique, __first, __last);
}
- _LIBCPP_HIDE_FROM_ABI flat_map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
+ flat_map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
: flat_map(__il.begin(), __il.end(), __comp) {}
template <class _Allocator>
requires __allocator_ctor_constraint<_Allocator>
- _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
flat_map(initializer_list<value_type> __il, const key_compare& __comp, const _Allocator& __alloc)
: flat_map(__il.begin(), __il.end(), __comp, __alloc) {}
template <class _Allocator>
requires __allocator_ctor_constraint<_Allocator>
- _LIBCPP_HIDE_FROM_ABI flat_map(initializer_list<value_type> __il, const _Allocator& __alloc)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
+ flat_map(initializer_list<value_type> __il, const _Allocator& __alloc)
: flat_map(__il.begin(), __il.end(), __alloc) {}
- _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
flat_map(sorted_unique_t, initializer_list<value_type> __il, const key_compare& __comp = key_compare())
: flat_map(sorted_unique, __il.begin(), __il.end(), __comp) {}
template <class _Allocator>
requires __allocator_ctor_constraint<_Allocator>
- _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
flat_map(sorted_unique_t, initializer_list<value_type> __il, const key_compare& __comp, const _Allocator& __alloc)
: flat_map(sorted_unique, __il.begin(), __il.end(), __comp, __alloc) {}
template <class _Allocator>
requires __allocator_ctor_constraint<_Allocator>
- _LIBCPP_HIDE_FROM_ABI flat_map(sorted_unique_t, initializer_list<value_type> __il, const _Allocator& __alloc)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
+ flat_map(sorted_unique_t, initializer_list<value_type> __il, const _Allocator& __alloc)
: flat_map(sorted_unique, __il.begin(), __il.end(), __alloc) {}
- _LIBCPP_HIDE_FROM_ABI flat_map& operator=(initializer_list<value_type> __il) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map& operator=(initializer_list<value_type> __il) {
clear();
insert(__il);
return *this;
}
- _LIBCPP_HIDE_FROM_ABI flat_map& operator=(const flat_map&) = default;
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map& operator=(const flat_map&) = default;
- _LIBCPP_HIDE_FROM_ABI flat_map& operator=(flat_map&& __other) noexcept(
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map& operator=(flat_map&& __other) noexcept(
is_nothrow_move_assignable_v<_KeyContainer> && is_nothrow_move_assignable_v<_MappedContainer> &&
is_nothrow_move_assignable_v<_Compare>) {
// No matter what happens, we always want to clear the other container before returning
@@ -403,49 +411,65 @@ class flat_map {
}
// iterators
- _LIBCPP_HIDE_FROM_ABI iterator begin() noexcept {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator begin() noexcept {
return iterator(__containers_.keys.begin(), __containers_.values.begin());
}
- _LIBCPP_HIDE_FROM_ABI const_iterator begin() const noexcept {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator begin() const noexcept {
return const_iterator(__containers_.keys.begin(), __containers_.values.begin());
}
- _LIBCPP_HIDE_FROM_ABI iterator end() noexcept {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator end() noexcept {
return iterator(__containers_.keys.end(), __containers_.values.end());
}
- _LIBCPP_HIDE_FROM_ABI const_iterator end() const noexcept {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator end() const noexcept {
return const_iterator(__containers_.keys.end(), __containers_.values.end());
}
- _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() noexcept { return reverse_iterator(end()); }
- _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); }
- _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() noexcept { return reverse_iterator(begin()); }
- _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reverse_iterator rbegin() noexcept {
+ return reverse_iterator(end());
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator rbegin() const noexcept {
+ return const_reverse_iterator(end());
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 reverse_iterator rend() noexcept {
+ return reverse_iterator(begin());
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator rend() const noexcept {
+ return const_reverse_iterator(begin());
+ }
- _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const noexcept { return begin(); }
- _LIBCPP_HIDE_FROM_ABI const_iterator cend() const noexcept { return end(); }
- _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); }
- _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator cbegin() const noexcept { return begin(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator cend() const noexcept { return end(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator crbegin() const noexcept {
+ return const_reverse_iterator(end());
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_reverse_iterator crend() const noexcept {
+ return const_reverse_iterator(begin());
+ }
// [flat.map.capacity], capacity
- [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool empty() const noexcept { return __containers_.keys.empty(); }
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool empty() const noexcept {
+ return __containers_.keys.empty();
+ }
- _LIBCPP_HIDE_FROM_ABI size_type size() const noexcept { return __containers_.keys.size(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type size() const noexcept {
+ return __containers_.keys.size();
+ }
- _LIBCPP_HIDE_FROM_ABI size_type max_size() const noexcept {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type max_size() const noexcept {
return std::min<size_type>(__containers_.keys.max_size(), __containers_.values.max_size());
}
// [flat.map.access], element access
- _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __x)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& operator[](const key_type& __x)
requires is_constructible_v<mapped_type>
{
return try_emplace(__x).first->second;
}
- _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __x)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& operator[](key_type&& __x)
requires is_constructible_v<mapped_type>
{
return try_emplace(std::move(__x)).first->second;
@@ -454,11 +478,11 @@ class flat_map {
template <class _Kp>
requires(__is_compare_transparent && is_constructible_v<key_type, _Kp> && is_constructible_v<mapped_type> &&
!is_convertible_v<_Kp &&, const_iterator> && !is_convertible_v<_Kp &&, iterator>)
- _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](_Kp&& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& operator[](_Kp&& __x) {
return try_emplace(std::forward<_Kp>(__x)).first->second;
}
- _LIBCPP_HIDE_FROM_ABI mapped_type& at(const key_type& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& at(const key_type& __x) {
auto __it = find(__x);
if (__it == end()) {
std::__throw_out_of_range("flat_map::at(const key_type&): Key does not exist");
@@ -466,7 +490,7 @@ class flat_map {
return __it->second;
}
- _LIBCPP_HIDE_FROM_ABI const mapped_type& at(const key_type& __x) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const mapped_type& at(const key_type& __x) const {
auto __it = find(__x);
if (__it == end()) {
std::__throw_out_of_range("flat_map::at(const key_type&) const: Key does not exist");
@@ -476,7 +500,7 @@ class flat_map {
template <class _Kp>
requires __is_compare_transparent
- _LIBCPP_HIDE_FROM_ABI mapped_type& at(const _Kp& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& at(const _Kp& __x) {
auto __it = find(__x);
if (__it == end()) {
std::__throw_out_of_range("flat_map::at(const K&): Key does not exist");
@@ -486,7 +510,7 @@ class flat_map {
template <class _Kp>
requires __is_compare_transparent
- _LIBCPP_HIDE_FROM_ABI const mapped_type& at(const _Kp& __x) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const mapped_type& at(const _Kp& __x) const {
auto __it = find(__x);
if (__it == end()) {
std::__throw_out_of_range("flat_map::at(const K&) const: Key does not exist");
@@ -497,45 +521,49 @@ class flat_map {
// [flat.map.modifiers], modifiers
template <class... _Args>
requires is_constructible_v<pair<key_type, mapped_type>, _Args...>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> emplace(_Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> emplace(_Args&&... __args) {
std::pair<key_type, mapped_type> __pair(std::forward<_Args>(__args)...);
return __try_emplace(std::move(__pair.first), std::move(__pair.second));
}
template <class... _Args>
requires is_constructible_v<pair<key_type, mapped_type>, _Args...>
- _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __hint, _Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator emplace_hint(const_iterator __hint, _Args&&... __args) {
std::pair<key_type, mapped_type> __pair(std::forward<_Args>(__args)...);
return __try_emplace_hint(__hint, std::move(__pair.first), std::move(__pair.second)).first;
}
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __x) { return emplace(__x); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> insert(const value_type& __x) {
+ return emplace(__x);
+ }
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __x) { return emplace(std::move(__x)); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> insert(value_type&& __x) {
+ return emplace(std::move(__x));
+ }
- _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, const value_type& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __hint, const value_type& __x) {
return emplace_hint(__hint, __x);
}
- _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, value_type&& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __hint, value_type&& __x) {
return emplace_hint(__hint, std::move(__x));
}
template <class _PairLike>
requires is_constructible_v<pair<key_type, mapped_type>, _PairLike>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(_PairLike&& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> insert(_PairLike&& __x) {
return emplace(std::forward<_PairLike>(__x));
}
template <class _PairLike>
requires is_constructible_v<pair<key_type, mapped_type>, _PairLike>
- _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, _PairLike&& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator insert(const_iterator __hint, _PairLike&& __x) {
return emplace_hint(__hint, std::forward<_PairLike>(__x));
}
template <class _InputIterator>
requires __has_input_iterator_category<_InputIterator>::value
- _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert(_InputIterator __first, _InputIterator __last) {
if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>) {
__reserve(__last - __first);
}
@@ -544,7 +572,8 @@ class flat_map {
template <class _InputIterator>
requires __has_input_iterator_category<_InputIterator>::value
- _LIBCPP_HIDE_FROM_ABI void insert(sorted_unique_t, _InputIterator __first, _InputIterator __last) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
+ insert(sorted_unique_t, _InputIterator __first, _InputIterator __last) {
if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>) {
__reserve(__last - __first);
}
@@ -553,7 +582,7 @@ class flat_map {
}
template <_ContainerCompatibleRange<value_type> _Range>
- _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert_range(_Range&& __range) {
if constexpr (ranges::sized_range<_Range>) {
__reserve(ranges::size(__range));
}
@@ -561,19 +590,22 @@ class flat_map {
__append_sort_merge_unique</*WasSorted = */ false>(ranges::begin(__range), ranges::end(__range));
}
- _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert(initializer_list<value_type> __il) {
+ insert(__il.begin(), __il.end());
+ }
- _LIBCPP_HIDE_FROM_ABI void insert(sorted_unique_t, initializer_list<value_type> __il) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void insert(sorted_unique_t, initializer_list<value_type> __il) {
insert(sorted_unique, __il.begin(), __il.end());
}
- _LIBCPP_HIDE_FROM_ABI containers extract() && {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 containers extract() && {
auto __guard = std::__make_scope_guard([&]() noexcept { clear() /* noexcept */; });
auto __ret = std::move(__containers_);
return __ret;
}
- _LIBCPP_HIDE_FROM_ABI void replace(key_container_type&& __key_cont, mapped_container_type&& __mapped_cont) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
+ replace(key_container_type&& __key_cont, mapped_container_type&& __mapped_cont) {
_LIBCPP_ASSERT_VALID_INPUT_RANGE(
__key_cont.size() == __mapped_cont.size(), "flat_map keys and mapped containers have different size");
@@ -587,13 +619,15 @@ class flat_map {
template <class... _Args>
requires is_constructible_v<mapped_type, _Args...>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(const key_type& __key, _Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
+ try_emplace(const key_type& __key, _Args&&... __args) {
return __try_emplace(__key, std::forward<_Args>(__args)...);
}
template <class... _Args>
requires is_constructible_v<mapped_type, _Args...>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(key_type&& __key, _Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
+ try_emplace(key_type&& __key, _Args&&... __args) {
return __try_emplace(std::move(__key), std::forward<_Args>(__args)...);
}
@@ -601,75 +635,84 @@ class flat_map {
requires(__is_compare_transparent && is_constructible_v<key_type, _Kp> &&
is_constructible_v<mapped_type, _Args...> && !is_convertible_v<_Kp &&, const_iterator> &&
!is_convertible_v<_Kp &&, iterator>)
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(_Kp&& __key, _Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool> try_emplace(_Kp&& __key, _Args&&... __args) {
return __try_emplace(std::forward<_Kp>(__key), std::forward<_Args>(__args)...);
}
template <class... _Args>
requires is_constructible_v<mapped_type, _Args...>
- _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __hint, const key_type& __key, _Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator
+ try_emplace(const_iterator __hint, const key_type& __key, _Args&&... __args) {
return __try_emplace_hint(__hint, __key, std::forward<_Args>(__args)...).first;
}
template <class... _Args>
requires is_constructible_v<mapped_type, _Args...>
- _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __hint, key_type&& __key, _Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator
+ try_emplace(const_iterator __hint, key_type&& __key, _Args&&... __args) {
return __try_emplace_hint(__hint, std::move(__key), std::forward<_Args>(__args)...).first;
}
template <class _Kp, class... _Args>
requires __is_compare_transparent && is_constructible_v<key_type, _Kp> && is_constructible_v<mapped_type, _Args...>
- _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __hint, _Kp&& __key, _Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator
+ try_emplace(const_iterator __hint, _Kp&& __key, _Args&&... __args) {
return __try_emplace_hint(__hint, std::forward<_Kp>(__key), std::forward<_Args>(__args)...).first;
}
template <class _Mapped>
requires is_assignable_v<mapped_type&, _Mapped> && is_constructible_v<mapped_type, _Mapped>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert_or_assign(const key_type& __key, _Mapped&& __obj) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
+ insert_or_assign(const key_type& __key, _Mapped&& __obj) {
return __insert_or_assign(__key, std::forward<_Mapped>(__obj));
}
template <class _Mapped>
requires is_assignable_v<mapped_type&, _Mapped> && is_constructible_v<mapped_type, _Mapped>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert_or_assign(key_type&& __key, _Mapped&& __obj) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
+ insert_or_assign(key_type&& __key, _Mapped&& __obj) {
return __insert_or_assign(std::move(__key), std::forward<_Mapped>(__obj));
}
template <class _Kp, class _Mapped>
requires __is_compare_transparent && is_constructible_v<key_type, _Kp> && is_assignable_v<mapped_type&, _Mapped> &&
is_constructible_v<mapped_type, _Mapped>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert_or_assign(_Kp&& __key, _Mapped&& __obj) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
+ insert_or_assign(_Kp&& __key, _Mapped&& __obj) {
return __insert_or_assign(std::forward<_Kp>(__key), std::forward<_Mapped>(__obj));
}
template <class _Mapped>
requires is_assignable_v<mapped_type&, _Mapped> && is_constructible_v<mapped_type, _Mapped>
- _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __hint, const key_type& __key, _Mapped&& __obj) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator
+ insert_or_assign(const_iterator __hint, const key_type& __key, _Mapped&& __obj) {
return __insert_or_assign(__hint, __key, std::forward<_Mapped>(__obj));
}
template <class _Mapped>
requires is_assignable_v<mapped_type&, _Mapped> && is_constructible_v<mapped_type, _Mapped>
- _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __hint, key_type&& __key, _Mapped&& __obj) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator
+ insert_or_assign(const_iterator __hint, key_type&& __key, _Mapped&& __obj) {
return __insert_or_assign(__hint, std::move(__key), std::forward<_Mapped>(__obj));
}
template <class _Kp, class _Mapped>
requires __is_compare_transparent && is_constructible_v<key_type, _Kp> && is_assignable_v<mapped_type&, _Mapped> &&
is_constructible_v<mapped_type, _Mapped>
- _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __hint, _Kp&& __key, _Mapped&& __obj) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator
+ insert_or_assign(const_iterator __hint, _Kp&& __key, _Mapped&& __obj) {
return __insert_or_assign(__hint, std::forward<_Kp>(__key), std::forward<_Mapped>(__obj));
}
- _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __position) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator erase(iterator __position) {
return __erase(__position.__key_iter_, __position.__mapped_iter_);
}
- _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator erase(const_iterator __position) {
return __erase(__position.__key_iter_, __position.__mapped_iter_);
}
- _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type erase(const key_type& __x) {
auto __iter = find(__x);
if (__iter != end()) {
erase(__iter);
@@ -681,14 +724,14 @@ class flat_map {
template <class _Kp>
requires(__is_compare_transparent && !is_convertible_v<_Kp &&, iterator> &&
!is_convertible_v<_Kp &&, const_iterator>)
- _LIBCPP_HIDE_FROM_ABI size_type erase(_Kp&& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type erase(_Kp&& __x) {
auto [__first, __last] = equal_range(__x);
auto __res = __last - __first;
erase(__first, __last);
return __res;
}
- _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator erase(const_iterator __first, const_iterator __last) {
auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
auto __key_it = __containers_.keys.erase(__first.__key_iter_, __last.__key_iter_);
auto __mapped_it = __containers_.values.erase(__first.__mapped_iter_, __last.__mapped_iter_);
@@ -696,7 +739,7 @@ class flat_map {
return iterator(std::move(__key_it), std::move(__mapped_it));
}
- _LIBCPP_HIDE_FROM_ABI void swap(flat_map& __y) noexcept {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void swap(flat_map& __y) noexcept {
// warning: The spec has unconditional noexcept, which means that
// if any of the following functions throw an exception,
// std::terminate will be called.
@@ -706,133 +749,156 @@ class flat_map {
ranges::swap(__containers_.values, __y.__containers_.values);
}
- _LIBCPP_HIDE_FROM_ABI void clear() noexcept {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void clear() noexcept {
__containers_.keys.clear();
__containers_.values.clear();
}
// observers
- _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __compare_; }
- _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return value_compare(__compare_); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 key_compare key_comp() const { return __compare_; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 value_compare value_comp() const {
+ return value_compare(__compare_);
+ }
- _LIBCPP_HIDE_FROM_ABI const key_container_type& keys() const noexcept { return __containers_.keys; }
- _LIBCPP_HIDE_FROM_ABI const mapped_container_type& values() const noexcept { return __containers_.values; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const key_container_type& keys() const noexcept {
+ return __containers_.keys;
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const mapped_container_type& values() const noexcept {
+ return __containers_.values;
+ }
// map operations
- _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __x) { return __find_impl(*this, __x); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator find(const key_type& __x) {
+ return __find_impl(*this, __x);
+ }
- _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __x) const { return __find_impl(*this, __x); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator find(const key_type& __x) const {
+ return __find_impl(*this, __x);
+ }
template <class _Kp>
requires __is_compare_transparent
- _LIBCPP_HIDE_FROM_ABI iterator find(const _Kp& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator find(const _Kp& __x) {
return __find_impl(*this, __x);
}
template <class _Kp>
requires __is_compare_transparent
- _LIBCPP_HIDE_FROM_ABI const_iterator find(const _Kp& __x) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator find(const _Kp& __x) const {
return __find_impl(*this, __x);
}
- _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __x) const { return contains(__x) ? 1 : 0; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type count(const key_type& __x) const {
+ return contains(__x) ? 1 : 0;
+ }
template <class _Kp>
requires __is_compare_transparent
- _LIBCPP_HIDE_FROM_ABI size_type count(const _Kp& __x) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type count(const _Kp& __x) const {
return contains(__x) ? 1 : 0;
}
- _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __x) const { return find(__x) != end(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool contains(const key_type& __x) const {
+ return find(__x) != end();
+ }
template <class _Kp>
requires __is_compare_transparent
- _LIBCPP_HIDE_FROM_ABI bool contains(const _Kp& __x) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool contains(const _Kp& __x) const {
return find(__x) != end();
}
- _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __x) { return __lower_bound<iterator>(*this, __x); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator lower_bound(const key_type& __x) {
+ return __lower_bound<iterator>(*this, __x);
+ }
- _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __x) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator lower_bound(const key_type& __x) const {
return __lower_bound<const_iterator>(*this, __x);
}
template <class _Kp>
requires __is_compare_transparent
- _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _Kp& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator lower_bound(const _Kp& __x) {
return __lower_bound<iterator>(*this, __x);
}
template <class _Kp>
requires __is_compare_transparent
- _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _Kp& __x) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator lower_bound(const _Kp& __x) const {
return __lower_bound<const_iterator>(*this, __x);
}
- _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __x) { return __upper_bound<iterator>(*this, __x); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator upper_bound(const key_type& __x) {
+ return __upper_bound<iterator>(*this, __x);
+ }
- _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __x) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator upper_bound(const key_type& __x) const {
return __upper_bound<const_iterator>(*this, __x);
}
template <class _Kp>
requires __is_compare_transparent
- _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _Kp& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator upper_bound(const _Kp& __x) {
return __upper_bound<iterator>(*this, __x);
}
template <class _Kp>
requires __is_compare_transparent
- _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _Kp& __x) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 const_iterator upper_bound(const _Kp& __x) const {
return __upper_bound<const_iterator>(*this, __x);
}
- _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, iterator> equal_range(const key_type& __x) {
return __equal_range_impl(*this, __x);
}
- _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __x) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<const_iterator, const_iterator>
+ equal_range(const key_type& __x) const {
return __equal_range_impl(*this, __x);
}
template <class _Kp>
requires __is_compare_transparent
- _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _Kp& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, iterator> equal_range(const _Kp& __x) {
return __equal_range_impl(*this, __x);
}
template <class _Kp>
requires __is_compare_transparent
- _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _Kp& __x) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<const_iterator, const_iterator>
+ equal_range(const _Kp& __x) const {
return __equal_range_impl(*this, __x);
}
- friend _LIBCPP_HIDE_FROM_ABI bool operator==(const flat_map& __x, const flat_map& __y) {
+ friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator==(const flat_map& __x, const flat_map& __y) {
return ranges::equal(__x, __y);
}
- friend _LIBCPP_HIDE_FROM_ABI auto operator<=>(const flat_map& __x, const flat_map& __y) {
+ friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 auto
+ operator<=>(const flat_map& __x, const flat_map& __y) {
return std::lexicographical_compare_three_way(
__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
}
- friend _LIBCPP_HIDE_FROM_ABI void swap(flat_map& __x, flat_map& __y) noexcept { __x.swap(__y); }
+ friend _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void swap(flat_map& __x, flat_map& __y) noexcept {
+ __x.swap(__y);
+ }
private:
struct __ctor_uses_allocator_tag {
- explicit _LIBCPP_HIDE_FROM_ABI __ctor_uses_allocator_tag() = default;
+ explicit _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __ctor_uses_allocator_tag() = default;
};
struct __ctor_uses_allocator_empty_tag {
- explicit _LIBCPP_HIDE_FROM_ABI __ctor_uses_allocator_empty_tag() = default;
+ explicit _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __ctor_uses_allocator_empty_tag() = default;
};
template <class _Allocator, class _KeyCont, class _MappedCont, class... _CompArg>
requires __allocator_ctor_constraint<_Allocator>
- _LIBCPP_HIDE_FROM_ABI
- flat_map(__ctor_uses_allocator_tag,
- const _Allocator& __alloc,
- _KeyCont&& __key_cont,
- _MappedCont&& __mapped_cont,
- _CompArg&&... __comp)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 flat_map(
+ __ctor_uses_allocator_tag,
+ const _Allocator& __alloc,
+ _KeyCont&& __key_cont,
+ _MappedCont&& __mapped_cont,
+ _CompArg&&... __comp)
: __containers_{.keys = std::make_obj_using_allocator<key_container_type>(
__alloc, std::forward<_KeyCont>(__key_cont)),
.values = std::make_obj_using_allocator<mapped_container_type>(
@@ -841,12 +907,13 @@ class flat_map {
template <class _Allocator, class... _CompArg>
requires __allocator_ctor_constraint<_Allocator>
- _LIBCPP_HIDE_FROM_ABI flat_map(__ctor_uses_allocator_empty_tag, const _Allocator& __alloc, _CompArg&&... __comp)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
+ flat_map(__ctor_uses_allocator_empty_tag, const _Allocator& __alloc, _CompArg&&... __comp)
: __containers_{.keys = std::make_obj_using_allocator<key_container_type>(__alloc),
.values = std::make_obj_using_allocator<mapped_container_type>(__alloc)},
__compare_(std::forward<_CompArg>(__comp)...) {}
- _LIBCPP_HIDE_FROM_ABI bool __is_sorted_and_unique(auto&& __key_container) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool __is_sorted_and_unique(auto&& __key_container) const {
auto __greater_or_equal_to = [this](const auto& __x, const auto& __y) { return !__compare_(__x, __y); };
return ranges::adjacent_find(__key_container, __greater_or_equal_to) == ranges::end(__key_container);
}
@@ -854,7 +921,7 @@ class flat_map {
// This function is only used in constructors. So there is not exception handling in this function.
// If the function exits via an exception, there will be no flat_map object constructed, thus, there
// is no invariant state to preserve
- _LIBCPP_HIDE_FROM_ABI void __sort_and_unique() {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __sort_and_unique() {
auto __zv = ranges::views::zip(__containers_.keys, __containers_.values);
ranges::sort(__zv, __compare_, [](const auto& __p) -> decltype(auto) { return std::get<0>(__p); });
auto __dup_start = ranges::unique(__zv, __key_equiv(__compare_)).begin();
@@ -864,7 +931,8 @@ class flat_map {
}
template <bool _WasSorted, class _InputIterator, class _Sentinel>
- _LIBCPP_HIDE_FROM_ABI void __append_sort_merge_unique(_InputIterator __first, _Sentinel __last) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
+ __append_sort_merge_unique(_InputIterator __first, _Sentinel __last) {
auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
size_t __num_of_appended = __flat_map_utils::__append(*this, std::move(__first), std::move(__last));
if (__num_of_appended != 0) {
@@ -892,7 +960,7 @@ class flat_map {
}
template <class _Self, class _Kp>
- _LIBCPP_HIDE_FROM_ABI static auto __find_impl(_Self&& __self, const _Kp& __key) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static auto __find_impl(_Self&& __self, const _Kp& __key) {
auto __it = __self.lower_bound(__key);
auto __last = __self.end();
if (__it == __last || __self.__compare_(__key, __it->first)) {
@@ -902,7 +970,7 @@ class flat_map {
}
template <class _Self, class _Kp>
- _LIBCPP_HIDE_FROM_ABI static auto __key_equal_range(_Self&& __self, const _Kp& __key) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static auto __key_equal_range(_Self&& __self, const _Kp& __key) {
auto __it = ranges::lower_bound(__self.__containers_.keys, __key, __self.__compare_);
auto __last = __self.__containers_.keys.end();
if (__it == __last || __self.__compare_(__key, *__it)) {
@@ -912,7 +980,7 @@ class flat_map {
}
template <class _Self, class _Kp>
- _LIBCPP_HIDE_FROM_ABI static auto __equal_range_impl(_Self&& __self, const _Kp& __key) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static auto __equal_range_impl(_Self&& __self, const _Kp& __key) {
auto [__key_first, __key_last] = __key_equal_range(__self, __key);
const auto __make_mapped_iter = [&](const auto& __key_iter) {
@@ -927,17 +995,18 @@ class flat_map {
}
template <class _Res, class _Self, class _Kp>
- _LIBCPP_HIDE_FROM_ABI static _Res __lower_bound(_Self&& __self, _Kp& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static _Res __lower_bound(_Self&& __self, _Kp& __x) {
return __binary_search<_Res>(__self, ranges::lower_bound, __x);
}
template <class _Res, class _Self, class _Kp>
- _LIBCPP_HIDE_FROM_ABI static _Res __upper_bound(_Self&& __self, _Kp& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static _Res __upper_bound(_Self&& __self, _Kp& __x) {
return __binary_search<_Res>(__self, ranges::upper_bound, __x);
}
template <class _Res, class _Self, class _Fn, class _Kp>
- _LIBCPP_HIDE_FROM_ABI static _Res __binary_search(_Self&& __self, _Fn __search_fn, _Kp& __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static _Res
+ __binary_search(_Self&& __self, _Fn __search_fn, _Kp& __x) {
auto __key_iter = __search_fn(__self.__containers_.keys, __x, __self.__compare_);
auto __mapped_iter =
__self.__containers_.values.begin() +
@@ -948,7 +1017,8 @@ class flat_map {
}
template <class _KeyArg, class... _MArgs>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __try_emplace(_KeyArg&& __key, _MArgs&&... __mapped_args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
+ __try_emplace(_KeyArg&& __key, _MArgs&&... __mapped_args) {
auto __key_it = ranges::lower_bound(__containers_.keys, __key, __compare_);
auto __mapped_it = __containers_.values.begin() + ranges::distance(__containers_.keys.begin(), __key_it);
@@ -967,7 +1037,7 @@ class flat_map {
}
template <class _Kp>
- _LIBCPP_HIDE_FROM_ABI bool __is_hint_correct(const_iterator __hint, _Kp&& __key) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool __is_hint_correct(const_iterator __hint, _Kp&& __key) {
if (__hint != cbegin() && !__compare_((__hint - 1)->first, __key)) {
return false;
}
@@ -978,7 +1048,8 @@ class flat_map {
}
template <class _Kp, class... _Args>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __try_emplace_hint(const_iterator __hint, _Kp&& __key, _Args&&... __args) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
+ __try_emplace_hint(const_iterator __hint, _Kp&& __key, _Args&&... __args) {
if (__is_hint_correct(__hint, __key)) {
if (__hint == cend() || __compare_(__key, __hint->first)) {
return {__flat_map_utils::__emplace_exact_pos(
@@ -999,7 +1070,8 @@ class flat_map {
}
template <class _Kp, class _Mapped>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_or_assign(_Kp&& __key, _Mapped&& __mapped) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
+ __insert_or_assign(_Kp&& __key, _Mapped&& __mapped) {
auto __r = try_emplace(std::forward<_Kp>(__key), std::forward<_Mapped>(__mapped));
if (!__r.second) {
__r.first->second = std::forward<_Mapped>(__mapped);
@@ -1008,7 +1080,8 @@ class flat_map {
}
template <class _Kp, class _Mapped>
- _LIBCPP_HIDE_FROM_ABI iterator __insert_or_assign(const_iterator __hint, _Kp&& __key, _Mapped&& __mapped) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator
+ __insert_or_assign(const_iterator __hint, _Kp&& __key, _Mapped&& __mapped) {
auto __r = __try_emplace_hint(__hint, std::forward<_Kp>(__key), std::forward<_Mapped>(__mapped));
if (!__r.second) {
__r.first->second = std::forward<_Mapped>(__mapped);
@@ -1016,7 +1089,7 @@ class flat_map {
return __r.first;
}
- _LIBCPP_HIDE_FROM_ABI void __reserve(size_t __size) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __reserve(size_t __size) {
if constexpr (requires { __containers_.keys.reserve(__size); }) {
__containers_.keys.reserve(__size);
}
@@ -1027,7 +1100,8 @@ class flat_map {
}
template <class _KIter, class _MIter>
- _LIBCPP_HIDE_FROM_ABI iterator __erase(_KIter __key_iter_to_remove, _MIter __mapped_iter_to_remove) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator
+ __erase(_KIter __key_iter_to_remove, _MIter __mapped_iter_to_remove) {
auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
auto __key_iter = __containers_.keys.erase(__key_iter_to_remove);
auto __mapped_iter = __containers_.values.erase(__mapped_iter_to_remove);
@@ -1037,7 +1111,8 @@ class flat_map {
template <class _Key2, class _Tp2, class _Compare2, class _KeyContainer2, class _MappedContainer2, class _Predicate>
friend typename flat_map<_Key2, _Tp2, _Compare2, _KeyContainer2, _MappedContainer2>::size_type
- erase_if(flat_map<_Key2, _Tp2, _Compare2, _KeyContainer2, _MappedContainer2>&, _Predicate);
+ _LIBCPP_CONSTEXPR_SINCE_CXX26
+ erase_if(flat_map<_Key2, _Tp2, _Compare2, _KeyContainer2, _MappedContainer2>&, _Predicate);
friend __flat_map_utils;
@@ -1045,8 +1120,9 @@ class flat_map {
_LIBCPP_NO_UNIQUE_ADDRESS key_compare __compare_;
struct __key_equiv {
- _LIBCPP_HIDE_FROM_ABI __key_equiv(key_compare __c) : __comp_(__c) {}
- _LIBCPP_HIDE_FROM_ABI bool operator()(const_reference __x, const_reference __y) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_equiv(key_compare __c) : __comp_(__c) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool
+ operator()(const_reference __x, const_reference __y) const {
return !__comp_(std::get<0>(__x), std::get<0>(__y)) && !__comp_(std::get<0>(__y), std::get<0>(__x));
}
key_compare __comp_;
@@ -1169,8 +1245,9 @@ struct uses_allocator<flat_map<_Key, _Tp, _Compare, _KeyContainer, _MappedContai
: bool_constant<uses_allocator_v<_KeyContainer, _Allocator> && uses_allocator_v<_MappedContainer, _Allocator>> {};
template <class _Key, class _Tp, class _Compare, class _KeyContainer, class _MappedContainer, class _Predicate>
-_LIBCPP_HIDE_FROM_ABI typename flat_map<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>::size_type
-erase_if(flat_map<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>& __flat_map, _Predicate __pred) {
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
+ typename flat_map<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>::size_type
+ erase_if(flat_map<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>& __flat_map, _Predicate __pred) {
auto __zv = ranges::views::zip(__flat_map.__containers_.keys, __flat_map.__containers_.values);
auto __first = __zv.begin();
auto __last = __zv.end();
diff --git a/libcxx/include/__flat_map/key_value_iterator.h b/libcxx/include/__flat_map/key_value_iterator.h
index 3ebb653deb197..f163dfc28706d 100644
--- a/libcxx/include/__flat_map/key_value_iterator.h
+++ b/libcxx/include/__flat_map/key_value_iterator.h
@@ -46,7 +46,7 @@ struct __key_value_iterator {
struct __arrow_proxy {
__reference __ref_;
- _LIBCPP_HIDE_FROM_ABI __reference* operator->() { return std::addressof(__ref_); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __reference* operator->() { return std::addressof(__ref_); }
};
__key_iterator __key_iter_;
@@ -69,99 +69,113 @@ struct __key_value_iterator {
_LIBCPP_HIDE_FROM_ABI __key_value_iterator() = default;
- _LIBCPP_HIDE_FROM_ABI __key_value_iterator(__key_value_iterator<_Owner, _KeyContainer, _MappedContainer, !_Const> __i)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
+ __key_value_iterator(__key_value_iterator<_Owner, _KeyContainer, _MappedContainer, !_Const> __i)
requires _Const && convertible_to<typename _KeyContainer::iterator, __key_iterator> &&
convertible_to<typename _MappedContainer::iterator, __mapped_iterator>
: __key_iter_(std::move(__i.__key_iter_)), __mapped_iter_(std::move(__i.__mapped_iter_)) {}
- _LIBCPP_HIDE_FROM_ABI __key_value_iterator(__key_iterator __key_iter, __mapped_iterator __mapped_iter)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26
+ __key_value_iterator(__key_iterator __key_iter, __mapped_iterator __mapped_iter)
: __key_iter_(std::move(__key_iter)), __mapped_iter_(std::move(__mapped_iter)) {}
- _LIBCPP_HIDE_FROM_ABI __reference operator*() const { return __reference(*__key_iter_, *__mapped_iter_); }
- _LIBCPP_HIDE_FROM_ABI __arrow_proxy operator->() const { return __arrow_proxy{**this}; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __reference operator*() const {
+ return __reference(*__key_iter_, *__mapped_iter_);
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __arrow_proxy operator->() const { return __arrow_proxy{**this}; }
- _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator++() {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_value_iterator& operator++() {
++__key_iter_;
++__mapped_iter_;
return *this;
}
- _LIBCPP_HIDE_FROM_ABI __key_value_iterator operator++(int) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_value_iterator operator++(int) {
__key_value_iterator __tmp(*this);
++*this;
return __tmp;
}
- _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator--() {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_value_iterator& operator--() {
--__key_iter_;
--__mapped_iter_;
return *this;
}
- _LIBCPP_HIDE_FROM_ABI __key_value_iterator operator--(int) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_value_iterator operator--(int) {
__key_value_iterator __tmp(*this);
--*this;
return __tmp;
}
- _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator+=(difference_type __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_value_iterator& operator+=(difference_type __x) {
__key_iter_ += __x;
__mapped_iter_ += __x;
return *this;
}
- _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator-=(difference_type __x) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __key_value_iterator& operator-=(difference_type __x) {
__key_iter_ -= __x;
__mapped_iter_ -= __x;
return *this;
}
- _LIBCPP_HIDE_FROM_ABI __reference operator[](difference_type __n) const { return *(*this + __n); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __reference operator[](difference_type __n) const {
+ return *(*this + __n);
+ }
- _LIBCPP_HIDE_FROM_ABI friend constexpr bool
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend bool
operator==(const __key_value_iterator& __x, const __key_value_iterator& __y) {
return __x.__key_iter_ == __y.__key_iter_;
}
- _LIBCPP_HIDE_FROM_ABI friend bool operator<(const __key_value_iterator& __x, const __key_value_iterator& __y) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend bool
+ operator<(const __key_value_iterator& __x, const __key_value_iterator& __y) {
return __x.__key_iter_ < __y.__key_iter_;
}
- _LIBCPP_HIDE_FROM_ABI friend bool operator>(const __key_value_iterator& __x, const __key_value_iterator& __y) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend bool
+ operator>(const __key_value_iterator& __x, const __key_value_iterator& __y) {
return __y < __x;
}
- _LIBCPP_HIDE_FROM_ABI friend bool operator<=(const __key_value_iterator& __x, const __key_value_iterator& __y) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend bool
+ operator<=(const __key_value_iterator& __x, const __key_value_iterator& __y) {
return !(__y < __x);
}
- _LIBCPP_HIDE_FROM_ABI friend bool operator>=(const __key_value_iterator& __x, const __key_value_iterator& __y) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend bool
+ operator>=(const __key_value_iterator& __x, const __key_value_iterator& __y) {
return !(__x < __y);
}
- _LIBCPP_HIDE_FROM_ABI friend auto operator<=>(const __key_value_iterator& __x, const __key_value_iterator& __y)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend auto
+ operator<=>(const __key_value_iterator& __x, const __key_value_iterator& __y)
requires three_way_comparable<__key_iterator>
{
return __x.__key_iter_ <=> __y.__key_iter_;
}
- _LIBCPP_HIDE_FROM_ABI friend __key_value_iterator operator+(const __key_value_iterator& __i, difference_type __n) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend __key_value_iterator
+ operator+(const __key_value_iterator& __i, difference_type __n) {
auto __tmp = __i;
__tmp += __n;
return __tmp;
}
- _LIBCPP_HIDE_FROM_ABI friend __key_value_iterator operator+(difference_type __n, const __key_value_iterator& __i) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend __key_value_iterator
+ operator+(difference_type __n, const __key_value_iterator& __i) {
return __i + __n;
}
- _LIBCPP_HIDE_FROM_ABI friend __key_value_iterator operator-(const __key_value_iterator& __i, difference_type __n) {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend __key_value_iterator
+ operator-(const __key_value_iterator& __i, difference_type __n) {
auto __tmp = __i;
__tmp -= __n;
return __tmp;
}
- _LIBCPP_HIDE_FROM_ABI friend difference_type
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 friend difference_type
operator-(const __key_value_iterator& __x, const __key_value_iterator& __y) {
return difference_type(__x.__key_iter_ - __y.__key_iter_);
}
diff --git a/libcxx/include/__flat_map/utils.h b/libcxx/include/__flat_map/utils.h
index acb7dca7ffe96..27687ae8de3bc 100644
--- a/libcxx/include/__flat_map/utils.h
+++ b/libcxx/include/__flat_map/utils.h
@@ -35,7 +35,7 @@ struct __flat_map_utils {
// roll back the changes it made to the map. If it cannot roll back the changes, it will
// clear the map.
template <class _Map, class _IterK, class _IterM, class _KeyArg, class... _MArgs>
- _LIBCPP_HIDE_FROM_ABI static typename _Map::iterator __emplace_exact_pos(
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static typename _Map::iterator __emplace_exact_pos(
_Map& __map, _IterK&& __it_key, _IterM&& __it_mapped, _KeyArg&& __key, _MArgs&&... __mapped_args) {
auto __on_key_failed = std::__make_exception_guard([&]() noexcept {
using _KeyContainer = typename _Map::key_container_type;
@@ -82,7 +82,7 @@ struct __flat_map_utils {
// TODO: We could optimize this, see
// https://github.com/llvm/llvm-project/issues/108624
template <class _Map, class _InputIterator, class _Sentinel>
- _LIBCPP_HIDE_FROM_ABI static typename _Map::size_type
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static typename _Map::size_type
__append(_Map& __map, _InputIterator __first, _Sentinel __last) {
typename _Map::size_type __num_appended = 0;
for (; __first != __last; ++__first) {
diff --git a/libcxx/test/std/containers/Emplaceable.h b/libcxx/test/std/containers/Emplaceable.h
index afc4e2e38b0eb..48d8eab0a9a09 100644
--- a/libcxx/test/std/containers/Emplaceable.h
+++ b/libcxx/test/std/containers/Emplaceable.h
@@ -22,13 +22,13 @@ class Emplaceable {
double double_;
public:
- Emplaceable() : int_(0), double_(0) {}
- Emplaceable(int i, double d) : int_(i), double_(d) {}
- Emplaceable(Emplaceable&& x) : int_(x.int_), double_(x.double_) {
+ TEST_CONSTEXPR Emplaceable() : int_(0), double_(0) {}
+ TEST_CONSTEXPR Emplaceable(int i, double d) : int_(i), double_(d) {}
+ TEST_CONSTEXPR Emplaceable(Emplaceable&& x) : int_(x.int_), double_(x.double_) {
x.int_ = 0;
x.double_ = 0;
}
- Emplaceable& operator=(Emplaceable&& x) {
+ TEST_CONSTEXPR Emplaceable& operator=(Emplaceable&& x) {
int_ = x.int_;
x.int_ = 0;
double_ = x.double_;
@@ -36,10 +36,12 @@ class Emplaceable {
return *this;
}
- bool operator==(const Emplaceable& x) const { return int_ == x.int_ && double_ == x.double_; }
- bool operator<(const Emplaceable& x) const { return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_); }
+ TEST_CONSTEXPR bool operator==(const Emplaceable& x) const { return int_ == x.int_ && double_ == x.double_; }
+ TEST_CONSTEXPR bool operator<(const Emplaceable& x) const {
+ return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);
+ }
- int get() const { return int_; }
+ TEST_CONSTEXPR int get() const { return int_; }
};
template <>
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/at.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/at.pass.cpp
index d30055bf1701c..bb4dd6453dd94 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/at.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/at.pass.cpp
@@ -18,6 +18,7 @@
#include <flat_map>
#include <functional>
#include <stdexcept>
+#include <type_traits>
#include <vector>
#include "MinSequenceContainer.h"
@@ -25,7 +26,7 @@
#include "test_macros.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using P = std::pair<int, double>;
P ar[] = {
P(1, 1.5),
@@ -49,10 +50,12 @@ void test() {
assert(m.at(4) == 4.5);
assert(m.at(5) == 5.5);
#ifndef TEST_HAS_NO_EXCEPTIONS
- try {
- TEST_IGNORE_NODISCARD m.at(6);
- assert(false);
- } catch (std::out_of_range&) {
+ if (!std::is_constant_evaluated()) {
+ try {
+ TEST_IGNORE_NODISCARD m.at(6);
+ assert(false);
+ } catch (std::out_of_range&) {
+ }
}
#endif
assert(m.at(7) == 7.5);
@@ -70,10 +73,12 @@ void test() {
assert(m.at(4) == 4.5);
assert(m.at(5) == 5.5);
#ifndef TEST_HAS_NO_EXCEPTIONS
- try {
- TEST_IGNORE_NODISCARD m.at(6);
- assert(false);
- } catch (std::out_of_range&) {
+ if (!std::is_constant_evaluated()) {
+ try {
+ TEST_IGNORE_NODISCARD m.at(6);
+ assert(false);
+ } catch (std::out_of_range&) {
+ }
}
#endif
assert(m.at(7) == 7.5);
@@ -82,11 +87,25 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/at_transparent.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/at_transparent.pass.cpp
index 456f12e0c0d29..7aa69b5ab5184 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/at_transparent.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/at_transparent.pass.cpp
@@ -35,7 +35,7 @@ static_assert(!CanAt<NonTransparentMap>);
static_assert(!CanAt<const NonTransparentMap>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using P = std::pair<int, double>;
P ar[] = {
P(1, 1.5),
@@ -60,10 +60,12 @@ void test() {
assert(m.at(Transparent<int>{4}) == 4.5);
assert(m.at(Transparent<int>{5}) == 5.5);
#ifndef TEST_HAS_NO_EXCEPTIONS
- try {
- TEST_IGNORE_NODISCARD m.at(Transparent<int>{6});
- assert(false);
- } catch (std::out_of_range&) {
+ if (!std::is_constant_evaluated()) {
+ try {
+ TEST_IGNORE_NODISCARD m.at(Transparent<int>{6});
+ assert(false);
+ } catch (std::out_of_range&) {
+ }
}
#endif
assert(m.at(Transparent<int>{7}) == 7.5);
@@ -81,10 +83,12 @@ void test() {
assert(m.at(Transparent<int>{4}) == 4.5);
assert(m.at(Transparent<int>{5}) == 5.5);
#ifndef TEST_HAS_NO_EXCEPTIONS
- try {
- TEST_IGNORE_NODISCARD m.at(Transparent<int>{6});
- assert(false);
- } catch (std::out_of_range&) {
+ if (!std::is_constant_evaluated()) {
+ try {
+ TEST_IGNORE_NODISCARD m.at(Transparent<int>{6});
+ assert(false);
+ } catch (std::out_of_range&) {
+ }
}
#endif
assert(m.at(Transparent<int>{7}) == 7.5);
@@ -93,9 +97,14 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
{
@@ -107,5 +116,14 @@ int main(int, char**) {
assert(transparent_used);
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/index_key.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/index_key.pass.cpp
index ea2f5d800878a..a7d613de399ed 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/index_key.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/index_key.pass.cpp
@@ -16,6 +16,7 @@
#include <deque>
#include <flat_map>
#include <functional>
+#include <type_traits>
#include <vector>
#include "MinSequenceContainer.h"
@@ -31,7 +32,7 @@ static_assert(CanIndex<std::flat_map<int, double>, const int&>);
static_assert(!CanIndex<std::flat_map<int, NoDefaultCtr>, const int&>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using P = std::pair<int, double>;
P ar[] = {
P(1, 1.5),
@@ -58,13 +59,18 @@ void test() {
assert(m.size() == 8);
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
- {
+ if (!std::is_constant_evaluated()) {
auto index_func = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
const typename FlatMap::key_type key = key_arg;
@@ -73,5 +79,16 @@ int main(int, char**) {
};
test_emplace_exception_guarantee(index_func);
}
+
+ return true;
+}
+
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/index_rv_key.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/index_rv_key.pass.cpp
index faacc3cfe8f96..4843e7c63b15c 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/index_rv_key.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/index_rv_key.pass.cpp
@@ -16,6 +16,7 @@
#include <deque>
#include <functional>
#include <cassert>
+#include <type_traits>
#include "MinSequenceContainer.h"
#include "../helpers.h"
@@ -31,7 +32,7 @@ static_assert(CanIndex<std::flat_map<int, double>, int&&>);
static_assert(!CanIndex<std::flat_map<int, NoDefaultCtr>, int&&>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
{
std::flat_map<MoveOnly, double, std::less<MoveOnly>, KeyContainer, ValueContainer> m;
ASSERT_SAME_TYPE(decltype(m[MoveOnly{}]), double&);
@@ -49,13 +50,18 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<MoveOnly>, std::vector<double>>();
- test<std::deque<MoveOnly>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<MoveOnly>, std::vector<double>>();
+ }
test<MinSequenceContainer<MoveOnly>, MinSequenceContainer<double>>();
test<std::vector<MoveOnly, min_allocator<MoveOnly>>, std::vector<double, min_allocator<double>>>();
- {
+ if (!std::is_constant_evaluated()) {
auto index_func = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
typename FlatMap::key_type key = key_arg;
@@ -64,5 +70,14 @@ int main(int, char**) {
};
test_emplace_exception_guarantee(index_func);
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/index_transparent.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/index_transparent.pass.cpp
index 24c08464f3158..ab9309d194ed1 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/index_transparent.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/index_transparent.pass.cpp
@@ -50,7 +50,7 @@ static_assert(!CanIndex<TransparentMap, TransparentMap::iterator>);
static_assert(!CanIndex<TransparentMap, TransparentMap::const_iterator>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using P = std::pair<int, double>;
P ar[] = {
P(1, 1.5),
@@ -81,11 +81,17 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
+
{
bool transparent_used = false;
TransparentComparator c(transparent_used);
@@ -94,7 +100,8 @@ int main(int, char**) {
m[ConvertibleTransparent<int>{3}];
assert(transparent_used);
}
- {
+
+ if (!std::is_constant_evaluated()) {
auto index_func = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
using Key = typename FlatMap::key_type;
@@ -103,5 +110,15 @@ int main(int, char**) {
};
test_emplace_exception_guarantee(index_func);
}
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/empty.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/empty.pass.cpp
index 05efe063c1e17..8027cab4b4260 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/empty.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/empty.pass.cpp
@@ -24,10 +24,10 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
- using M = std::flat_multimap<Key, Value, std::less<int>, KeyContainer, ValueContainer>;
+ using M = std::flat_map<Key, Value, std::less<int>, KeyContainer, ValueContainer>;
M m;
ASSERT_SAME_TYPE(decltype(m.empty()), bool);
ASSERT_NOEXCEPT(m.empty());
@@ -39,11 +39,25 @@ void test() {
assert(m.empty());
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/max_size.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/max_size.pass.cpp
index 87acdfd2cf625..ee01f8eb1dfe4 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/max_size.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/max_size.pass.cpp
@@ -24,7 +24,7 @@
#include "test_allocator.h"
#include "test_macros.h"
-int main(int, char**) {
+constexpr bool test() {
{
using A1 = limited_allocator<int, 10>;
using A2 = limited_allocator<int, 20>;
@@ -72,5 +72,15 @@ int main(int, char**) {
assert(c.max_size() <= max_dist);
assert(c.max_size() <= alloc_max_size(std::allocator<char>()));
}
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/size.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/size.pass.cpp
index 957a860450091..08cfb0e9da062 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/size.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/size.pass.cpp
@@ -16,6 +16,7 @@
#include <deque>
#include <flat_map>
#include <functional>
+#include <type_traits>
#include <vector>
#include "MinSequenceContainer.h"
@@ -23,7 +24,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using M = std::flat_map<int, char, std::less<int>, KeyContainer, ValueContainer>;
{
const M m = {{1, 'a'}, {1, 'b'}, {4, 'd'}, {5, 'e'}, {5, 'h'}};
@@ -45,7 +46,7 @@ void test() {
}
{
M m;
- std::size_t s = 1000000;
+ std::size_t s = std::is_constant_evaluated() ? 100 : 1000000;
for (auto i = 0u; i < s; ++i) {
m.emplace(i, 'a');
}
@@ -55,11 +56,25 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
- test<std::deque<int>, std::vector<char>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<char>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/alloc.pass.cpp
index 3f8d2ed332d6b..54dbe2309c43c 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/alloc.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/alloc.pass.cpp
@@ -14,6 +14,7 @@
// explicit flat_map(const Allocator& a);
#include <cassert>
+#include <deque>
#include <flat_map>
#include <functional>
#include <vector>
@@ -22,7 +23,23 @@
#include "test_allocator.h"
#include "../../../test_compare.h"
-int main(int, char**) {
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test() {
+ using A = test_allocator<short>;
+ using M =
+ std::flat_map<int,
+ long,
+ std::less<int>,
+ KeyContainer<int, test_allocator<int>>,
+ ValueContainer<long, test_allocator<long>>>;
+ M m(A(0, 5));
+ assert(m.empty());
+ assert(m.begin() == m.end());
+ assert(m.keys().get_allocator().get_id() == 5);
+ assert(m.values().get_allocator().get_id() == 5);
+}
+
+constexpr bool test() {
{
// The constructors in this subclause shall not participate in overload
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
@@ -53,20 +70,23 @@ int main(int, char**) {
static_assert(std::is_constructible_v<M, test_allocator<int>>);
static_assert(!std::is_convertible_v<test_allocator<int>, M>);
}
+
+ test<std::vector, std::vector>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
{
- using A = test_allocator<short>;
- using M =
- std::flat_map<int,
- long,
- std::less<int>,
- std::vector<int, test_allocator<int>>,
- std::vector<long, test_allocator<long>>>;
- M m(A(0, 5));
- assert(m.empty());
- assert(m.begin() == m.end());
- assert(m.keys().get_allocator().get_id() == 5);
- assert(m.values().get_allocator().get_id() == 5);
+ test<std::deque, std::deque>();
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/assign_initializer_list.pass.cpp
index 06bde71e79941..fd0d8c34fc7bd 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/assign_initializer_list.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/assign_initializer_list.pass.cpp
@@ -26,7 +26,7 @@
#include "test_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -36,7 +36,6 @@ void test() {
m = {{3, 0}, {1, 0}, {2, 0}, {2, 1}, {3, 1}, {4, 0}, {3, 2}, {5, 0}, {6, 0}, {5, 1}};
std::pair<int, int> expected[] = {{1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}};
assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
- LIBCPP_ASSERT(std::ranges::equal(m, expected));
}
{
M m = {{10, 1}, {8, 1}};
@@ -47,13 +46,28 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<int>>();
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
+
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/compare.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/compare.pass.cpp
index 40a1710f55e42..56c4699c32177 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/compare.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/compare.pass.cpp
@@ -20,48 +20,52 @@
#include <type_traits>
#include <vector>
+#include "MinSequenceContainer.h"
+#include "min_allocator.h"
#include "test_macros.h"
#include "../../../test_compare.h"
#include "test_allocator.h"
-int main(int, char**) {
+// explicit flat_map(const key_compare& comp);
+template <class KeyContainer, class ValueContainer>
+constexpr void test_compare() {
+ using Key = typename KeyContainer::value_type;
+ using Value = typename ValueContainer::value_type;
{
- // 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.
+ // The one-argument ctor is explicit.
+ using C = test_less<Key>;
+ static_assert(std::is_constructible_v<std::flat_map<Key, Value, C>, C>);
+ static_assert(!std::is_convertible_v<C, std::flat_map<Key, Value, C>>);
- using C = test_less<int>;
- using A1 = test_allocator<int>;
- using A2 = other_allocator<int>;
- using M1 = std::flat_map<int, int, C, std::vector<int, A1>, std::vector<int, A1>>;
- using M2 = std::flat_map<int, int, C, std::vector<int, A1>, std::vector<int, A2>>;
- using M3 = std::flat_map<int, int, C, std::vector<int, A2>, std::vector<int, A1>>;
- static_assert(std::is_constructible_v<M1, const C&, const A1&>);
- static_assert(!std::is_constructible_v<M1, const C&, const A2&>);
- static_assert(!std::is_constructible_v<M2, const C&, const A2&>);
- static_assert(!std::is_constructible_v<M3, const C&, const A2&>);
+ static_assert(std::is_constructible_v<std::flat_map<Key, Value>, std::less<Key>>);
+ static_assert(!std::is_convertible_v<std::less<Key>, std::flat_map<Key, Value>>);
}
{
- using C = test_less<int>;
- auto m = std::flat_map<int, char*, C>(C(3));
+ using C = test_less<Key>;
+ auto m = std::flat_map<Key, Value, C>(C(3));
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp() == C(3));
}
- {
- // The one-argument ctor is explicit.
- using C = test_less<int>;
- static_assert(std::is_constructible_v<std::flat_map<int, char*, C>, C>);
- static_assert(!std::is_convertible_v<C, std::flat_map<int, char*, C>>);
+}
- static_assert(std::is_constructible_v<std::flat_map<int, char*>, std::less<int>>);
- static_assert(!std::is_convertible_v<std::less<int>, std::flat_map<int, char*>>);
+// template <class Alloc>
+// flat_map(const key_compare& comp, const Alloc& a);
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test_compare_alloc() {
+ {
+ // If an allocator is given, it must be usable by both containers.
+ using A = test_allocator<int>;
+ using M = std::flat_map<int, int, std::less<>, KeyContainer<int>, ValueContainer<int, A>>;
+ static_assert(std::is_constructible_v<M, std::less<>>);
+ static_assert(!std::is_constructible_v<M, std::less<>, std::allocator<int>>);
+ static_assert(!std::is_constructible_v<M, std::less<>, A>);
}
{
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
- auto m = std::flat_map<int, short, C, std::vector<int, A1>, std::vector<short, A2>>(C(4), A1(5));
+ auto m = std::flat_map<int, short, C, KeyContainer<int, A1>, ValueContainer<short, A2>>(C(4), A1(5));
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp() == C(4));
@@ -70,24 +74,60 @@ int main(int, char**) {
}
{
// explicit(false)
- using C = test_less<int>;
- using A1 = test_allocator<int>;
- using A2 = test_allocator<short>;
- std::flat_map<int, short, C, std::deque<int, A1>, std::deque<short, A2>> m = {C(4), A1(5)};
+ using C = test_less<int>;
+ using A1 = test_allocator<int>;
+ using A2 = test_allocator<short>;
+ std::flat_map<int, short, C, KeyContainer<int, A1>, ValueContainer<short, A2>> m = {C(4), A1(5)};
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp() == C(4));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
+}
+
+constexpr bool test() {
{
- // If an allocator is given, it must be usable by both containers.
- using A = test_allocator<int>;
- using M = std::flat_map<int, int, std::less<>, std::vector<int>, std::vector<int, A>>;
- static_assert(std::is_constructible_v<M, std::less<>>);
- static_assert(!std::is_constructible_v<M, std::less<>, std::allocator<int>>);
- static_assert(!std::is_constructible_v<M, std::less<>, A>);
+ // 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 M1 = std::flat_map<int, int, C, std::vector<int, A1>, std::vector<int, A1>>;
+ using M2 = std::flat_map<int, int, C, std::vector<int, A1>, std::vector<int, A2>>;
+ using M3 = std::flat_map<int, int, C, std::vector<int, A2>, std::vector<int, A1>>;
+ static_assert(std::is_constructible_v<M1, const C&, const A1&>);
+ static_assert(!std::is_constructible_v<M1, const C&, const A2&>);
+ static_assert(!std::is_constructible_v<M2, const C&, const A2&>);
+ static_assert(!std::is_constructible_v<M3, const C&, const A2&>);
+ }
+
+ test_compare<std::vector<int>, std::vector<int>>();
+ test_compare<std::vector<int>, std::vector<double>>();
+ test_compare<MinSequenceContainer<int>, MinSequenceContainer<double>>();
+ test_compare<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
+ test_compare<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
+
+ test_compare_alloc<std::vector, std::vector>();
+
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test_compare<std::deque<int>, std::vector<double>>();
+ test_compare_alloc<std::deque, std::deque>();
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/containers.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/containers.pass.cpp
index 812e2c3e4f02a..560abf5151b6f 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/containers.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/containers.pass.cpp
@@ -30,49 +30,34 @@
#include "test_allocator.h"
#include "test_iterators.h"
#include "test_macros.h"
+#include "../helpers.h"
#include "../../../test_compare.h"
struct P {
int first;
int second;
template <class T, class U>
- bool operator==(const std::pair<T, U>& rhs) const {
+ constexpr bool operator==(const std::pair<T, U>& rhs) const {
return MoveOnly(first) == rhs.first && MoveOnly(second) == rhs.second;
}
};
-int main(int, char**) {
- {
- // 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_map<int, int, C, V1, V1>;
- using M2 = std::flat_map<int, int, C, V1, V2>;
- using M3 = std::flat_map<int, int, C, V2, V1>;
- static_assert(std::is_constructible_v<M1, const V1&, const V1&, const A1&>);
- static_assert(!std::is_constructible_v<M1, const V1&, const V1&, const A2&>);
- static_assert(!std::is_constructible_v<M2, const V1&, const V2&, const A2&>);
- static_assert(!std::is_constructible_v<M3, const V2&, const V1&, const A2&>);
-
- static_assert(std::is_constructible_v<M1, const V1&, const V1&, const C&, const A1&>);
- static_assert(!std::is_constructible_v<M1, const V1&, const V1&, const C&, const A2&>);
- static_assert(!std::is_constructible_v<M2, const V1&, const V2&, const C&, const A2&>);
- static_assert(!std::is_constructible_v<M3, const V2&, const V1&, const C&, const A2&>);
- }
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test() {
{
// flat_map(key_container_type , mapped_container_type)
- using M = std::flat_map<int, char>;
- std::vector<int> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
- std::vector<char> vs = {1, 2, 3, 4, 5, 6, 7, 8, 9};
- auto m = M(ks, vs);
- assert((m.keys() == std::vector<int>{1, 2, 3}));
- LIBCPP_ASSERT((m.values() == std::vector<char>{1, 4, 6}));
+ using M = std::flat_map<int, short, std::less<int>, KeyContainer<int>, ValueContainer<short>>;
+ KeyContainer<int> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
+ ValueContainer<short> vs = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+ auto m = M(ks, vs);
+ assert((m.keys() == KeyContainer<int>{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<short>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
// explicit(false)
M m2 = {ks, vs};
@@ -81,15 +66,21 @@ int main(int, char**) {
m = M(std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
- assert((m.keys() == std::vector<int>{1, 2, 3}));
- LIBCPP_ASSERT((m.values() == std::vector<char>{1, 4, 6}));
+ assert((m.keys() == KeyContainer<int>{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<short>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
}
{
// flat_map(key_container_type , mapped_container_type)
// move-only
P expected[] = {{3, 2}, {2, 1}, {1, 3}};
- using Ks = std::deque<int, min_allocator<int>>;
- using Vs = std::vector<MoveOnly, min_allocator<MoveOnly>>;
+ using Ks = KeyContainer<int, min_allocator<int>>;
+ using Vs = ValueContainer<MoveOnly, min_allocator<MoveOnly>>;
using M = std::flat_map<int, MoveOnly, std::greater<int>, Ks, Vs>;
Ks ks = {1, 3, 2};
Vs vs;
@@ -105,9 +96,9 @@ int main(int, char**) {
// flat_map(key_container_type , mapped_container_type)
// container's allocators are used
using A = test_allocator<int>;
- using M = std::flat_map<int, int, std::less<int>, std::vector<int, A>, std::deque<int, A>>;
- auto ks = std::vector<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(5));
- auto vs = std::deque<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(6));
+ using M = std::flat_map<int, int, std::less<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
+ auto ks = KeyContainer<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(5));
+ auto vs = ValueContainer<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(6));
auto m = M(std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
@@ -117,13 +108,19 @@ int main(int, char**) {
}
{
// flat_map(key_container_type , mapped_container_type, key_compare)
- using C = test_less<int>;
- using M = std::flat_map<int, char, C>;
- std::vector<int> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
- std::vector<char> vs = {1, 2, 3, 4, 5, 6, 7, 8, 9};
- auto m = M(ks, vs, C(4));
- assert((m.keys() == std::vector<int>{1, 2, 3}));
- LIBCPP_ASSERT((m.values() == std::vector<char>{1, 4, 6}));
+ using C = test_less<int>;
+ using M = std::flat_map<int, char, C, KeyContainer<int>, ValueContainer<char>>;
+ KeyContainer<int> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
+ ValueContainer<char> vs = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+ auto m = M(ks, vs, C(4));
+ assert((m.keys() == KeyContainer<int>{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<char>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
assert(m.key_comp() == C(4));
// explicit(false)
@@ -134,9 +131,9 @@ int main(int, char**) {
{
// flat_map(key_container_type , mapped_container_type, const Allocator&)
using A = test_allocator<int>;
- using M = std::flat_map<int, int, std::less<int>, std::vector<int, A>, std::deque<int, A>>;
- auto ks = std::vector<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(5));
- auto vs = std::deque<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(6));
+ using M = std::flat_map<int, int, std::less<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
+ auto ks = KeyContainer<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(5));
+ auto vs = ValueContainer<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(6));
auto m = M(ks, vs, A(4)); // replaces the allocators
assert(!ks.empty()); // it was an lvalue above
assert(!vs.empty()); // it was an lvalue above
@@ -148,9 +145,9 @@ int main(int, char**) {
// flat_map(key_container_type , mapped_container_type, const Allocator&)
// explicit(false)
using A = test_allocator<int>;
- using M = std::flat_map<int, int, std::less<int>, std::vector<int, A>, std::deque<int, A>>;
- auto ks = std::vector<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(5));
- auto vs = std::deque<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(6));
+ using M = std::flat_map<int, int, std::less<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
+ auto ks = KeyContainer<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(5));
+ auto vs = ValueContainer<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(6));
M m = {ks, vs, A(4)}; // implicit ctor
assert(!ks.empty()); // it was an lvalue above
assert(!vs.empty()); // it was an lvalue above
@@ -158,6 +155,7 @@ int main(int, char**) {
assert(m.keys().get_allocator() == A(4));
assert(m.values().get_allocator() == A(4));
}
+
{
// flat_map(key_container_type , mapped_container_type, key_compare, const Allocator&)
using C = test_less<int>;
@@ -167,7 +165,13 @@ int main(int, char**) {
std::vector<int, A> vs = {1, 2, 3, 4, 5, 6, 7, 8, 9};
auto m = M(ks, vs, C(4), A(5));
assert((m.keys() == std::vector<int, A>{1, 2, 3}));
- LIBCPP_ASSERT((m.values() == std::vector<int, A>{1, 4, 6}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<int>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
assert(m.key_comp() == C(4));
assert(m.keys().get_allocator() == A(5));
assert(m.values().get_allocator() == A(5));
@@ -179,6 +183,51 @@ int main(int, char**) {
assert(m2.keys().get_allocator() == A(5));
assert(m2.values().get_allocator() == A(5));
}
+}
+
+bool constexpr 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_map<int, int, C, V1, V1>;
+ using M2 = std::flat_map<int, int, C, V1, V2>;
+ using M3 = std::flat_map<int, int, C, V2, V1>;
+ static_assert(std::is_constructible_v<M1, const V1&, const V1&, const A1&>);
+ static_assert(!std::is_constructible_v<M1, const V1&, const V1&, const A2&>);
+ static_assert(!std::is_constructible_v<M2, const V1&, const V2&, const A2&>);
+ static_assert(!std::is_constructible_v<M3, const V2&, const V1&, const A2&>);
+
+ static_assert(std::is_constructible_v<M1, const V1&, const V1&, const C&, const A1&>);
+ static_assert(!std::is_constructible_v<M1, const V1&, const V1&, const C&, const A2&>);
+ static_assert(!std::is_constructible_v<M2, const V1&, const V2&, const C&, const A2&>);
+ static_assert(!std::is_constructible_v<M3, const V2&, const V1&, const C&, const A2&>);
+ }
+
+ test<std::vector, std::vector>();
+
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque, std::vector>();
+ test<std::deque, std::deque>();
+ }
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy.pass.cpp
index fcd0415088c1c..70fc3f7734bfd 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy.pass.cpp
@@ -13,6 +13,7 @@
// flat_map(const flat_map& m);
#include <cassert>
+#include <deque>
#include <flat_map>
#include <vector>
@@ -20,11 +21,12 @@
#include "../../../test_compare.h"
#include "test_allocator.h"
-int main(int, char**) {
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test() {
{
using C = test_less<int>;
- std::vector<int, test_allocator<int>> ks({1, 3, 5}, test_allocator<int>(6));
- std::vector<char, test_allocator<char>> vs({2, 2, 1}, test_allocator<char>(7));
+ KeyContainer<int, test_allocator<int>> ks({1, 3, 5}, test_allocator<int>(6));
+ ValueContainer<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 = mo;
@@ -44,8 +46,8 @@ int main(int, char**) {
}
{
using C = test_less<int>;
- using Ks = std::vector<int, other_allocator<int>>;
- using Vs = std::vector<char, other_allocator<char>>;
+ using Ks = KeyContainer<int, other_allocator<int>>;
+ using Vs = ValueContainer<char, other_allocator<char>>;
auto ks = Ks({1, 3, 5}, other_allocator<int>(6));
auto vs = Vs({2, 2, 1}, other_allocator<char>(7));
using M = std::flat_map<int, char, C, Ks, Vs>;
@@ -65,6 +67,26 @@ int main(int, char**) {
assert(mo.keys().get_allocator() == other_allocator<int>(6));
assert(mo.values().get_allocator() == other_allocator<char>(7));
}
+}
+
+constexpr bool test() {
+ test<std::vector, std::vector>();
+
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque, std::deque>();
+ }
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_alloc.pass.cpp
index cbda6ea853268..377b99a8cffb8 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_alloc.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_alloc.pass.cpp
@@ -22,7 +22,30 @@
#include "../../../test_compare.h"
#include "test_allocator.h"
-int main(int, char**) {
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test() {
+ using C = test_less<int>;
+ KeyContainer<int, test_allocator<int>> ks({1, 3, 5}, test_allocator<int>(6));
+ ValueContainer<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(mo, test_allocator<int>(3));
+
+ assert(m.key_comp() == C(5));
+ assert(m.keys() == ks);
+ assert(m.values() == vs);
+ assert(m.keys().get_allocator() == test_allocator<int>(3));
+ assert(m.values().get_allocator() == test_allocator<char>(3));
+
+ // mo is unchanged
+ assert(mo.key_comp() == C(5));
+ assert(mo.keys() == ks);
+ assert(mo.values() == vs);
+ assert(mo.keys().get_allocator() == test_allocator<int>(6));
+ assert(mo.values().get_allocator() == test_allocator<char>(7));
+}
+
+constexpr bool test() {
{
// The constructors in this subclause shall not participate in overload
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
@@ -41,27 +64,24 @@ int main(int, char**) {
static_assert(!std::is_constructible_v<M2, const M2&, const A2&>);
static_assert(!std::is_constructible_v<M3, const M3&, const A2&>);
}
- {
- using C = test_less<int>;
- std::vector<int, test_allocator<int>> ks({1, 3, 5}, test_allocator<int>(6));
- 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(mo, test_allocator<int>(3));
- assert(m.key_comp() == C(5));
- assert(m.keys() == ks);
- assert(m.values() == vs);
- assert(m.keys().get_allocator() == test_allocator<int>(3));
- assert(m.values().get_allocator() == test_allocator<char>(3));
+ test<std::vector, std::vector>();
- // mo is unchanged
- assert(mo.key_comp() == C(5));
- assert(mo.keys() == ks);
- assert(mo.values() == vs);
- assert(mo.keys().get_allocator() == test_allocator<int>(6));
- assert(mo.values().get_allocator() == test_allocator<char>(7));
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque, std::deque>();
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp
index 4f9797d5bf810..f0c8d8c2ccb98 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp
@@ -15,18 +15,20 @@
#include <deque>
#include <flat_map>
#include <functional>
+#include <type_traits>
#include <vector>
#include "test_macros.h"
#include "../../../test_compare.h"
#include "test_allocator.h"
-int main(int, char**) {
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test() {
{
// test_allocator is not propagated
using C = test_less<int>;
- std::vector<int, test_allocator<int>> ks({1, 3, 5}, test_allocator<int>(6));
- std::vector<char, test_allocator<char>> vs({2, 2, 1}, test_allocator<char>(7));
+ KeyContainer<int, test_allocator<int>> ks({1, 3, 5}, test_allocator<int>(6));
+ ValueContainer<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));
@@ -48,8 +50,8 @@ int main(int, char**) {
{
// other_allocator is propagated
using C = test_less<int>;
- using Ks = std::vector<int, other_allocator<int>>;
- using Vs = std::vector<char, other_allocator<char>>;
+ using Ks = KeyContainer<int, other_allocator<int>>;
+ using Vs = ValueContainer<char, other_allocator<char>>;
auto ks = Ks({1, 3, 5}, other_allocator<int>(6));
auto vs = Vs({2, 2, 1}, other_allocator<char>(7));
using M = std::flat_map<int, char, C, Ks, Vs>;
@@ -70,7 +72,7 @@ int main(int, char**) {
assert(mo.keys().get_allocator() == other_allocator<int>(6));
assert(mo.values().get_allocator() == other_allocator<char>(7));
}
- {
+ if (!std::is_constant_evaluated()) {
// comparator is copied and invariant is preserved
using M = std::flat_map<int, int, std::function<bool(int, int)>>;
M mo = M({{1, 2}, {3, 4}}, std::less<int>());
@@ -88,5 +90,26 @@ int main(int, char**) {
m = static_cast<const M&>(m);
assert((m == M{{1, 2}, {3, 4}}));
}
+}
+
+constexpr bool test() {
+ test<std::vector, std::vector>();
+
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque, std::deque>();
+ }
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/default.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/default.pass.cpp
index c5b94896b9293..bcf5f95ff9dcb 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/default.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/default.pass.cpp
@@ -24,23 +24,24 @@
#include "test_allocator.h"
struct DefaultCtableComp {
- explicit DefaultCtableComp() { default_constructed_ = true; }
- bool operator()(int, int) const { return false; }
+ constexpr explicit DefaultCtableComp() { default_constructed_ = true; }
+ constexpr bool operator()(int, int) const { return false; }
bool default_constructed_ = false;
};
-int main(int, char**) {
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test() {
{
- std::flat_map<int, char*> m;
+ std::flat_map<int, char*, std::less<int>, KeyContainer<int>, ValueContainer<char*>> m;
assert(m.empty());
}
{
// explicit(false)
- std::flat_map<int, char*> m = {};
+ std::flat_map<int, char*, std::less<int>, KeyContainer<int>, ValueContainer<char*>> m = {};
assert(m.empty());
}
{
- std::flat_map<int, char*, DefaultCtableComp, std::deque<int, min_allocator<int>>> m;
+ std::flat_map<int, char*, DefaultCtableComp, KeyContainer<int, min_allocator<int>>> m;
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp().default_constructed_);
@@ -49,13 +50,13 @@ int main(int, char**) {
using A1 = explicit_allocator<int>;
using A2 = explicit_allocator<char*>;
{
- std::flat_map<int, char*, DefaultCtableComp, std::vector<int, A1>, std::vector<char*, A2>> m;
+ std::flat_map<int, char*, DefaultCtableComp, KeyContainer<int, A1>, ValueContainer<char*, A2>> m;
assert(m.empty());
assert(m.key_comp().default_constructed_);
}
{
A1 a1;
- std::flat_map<int, int, DefaultCtableComp, std::vector<int, A1>, std::vector<int, A1>> m(a1);
+ std::flat_map<int, int, DefaultCtableComp, KeyContainer<int, A1>, ValueContainer<int, A1>> m(a1);
assert(m.empty());
assert(m.key_comp().default_constructed_);
}
@@ -63,10 +64,31 @@ int main(int, char**) {
{
// If an allocator is given, it must be usable by both containers.
using A = test_allocator<int>;
- using M = std::flat_map<int, int, std::less<>, std::vector<int>, std::vector<int, A>>;
+ using M = std::flat_map<int, int, std::less<>, KeyContainer<int>, ValueContainer<int, A>>;
static_assert(std::is_constructible_v<M>);
static_assert(!std::is_constructible_v<M, std::allocator<int>>);
static_assert(!std::is_constructible_v<M, A>);
}
+}
+
+constexpr bool test() {
+ test<std::vector, std::vector>();
+
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque, std::deque>();
+ }
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/default_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/default_noexcept.pass.cpp
index 790dfa4a02ed5..9fb6785a7cf1a 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/default_noexcept.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/default_noexcept.pass.cpp
@@ -28,11 +28,11 @@
#include "test_allocator.h"
struct ThrowingCtorComp {
- ThrowingCtorComp() noexcept(false) {}
- bool operator()(const auto&, const auto&) const { return false; }
+ constexpr ThrowingCtorComp() noexcept(false) {}
+ constexpr bool operator()(const auto&, const auto&) const { return false; }
};
-int main(int, char**) {
+constexpr bool test() {
#if defined(_LIBCPP_VERSION)
{
using C = std::flat_map<MoveOnly, MoveOnly>;
@@ -55,5 +55,15 @@ int main(int, char**) {
static_assert(!std::is_nothrow_default_constructible_v<C>);
C c;
}
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/dtor_noexcept.pass.cpp
index 1570b0fa14888..ea89e6a68281c 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/dtor_noexcept.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/dtor_noexcept.pass.cpp
@@ -23,35 +23,58 @@
#include "test_allocator.h"
struct ThrowingDtorComp {
- bool operator()(const auto&, const auto&) const;
- ~ThrowingDtorComp() noexcept(false) {}
+ constexpr bool operator()(const auto&, const auto&) const;
+ constexpr ~ThrowingDtorComp() noexcept(false) {}
};
-int main(int, char**) {
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test() {
{
- using C = std::flat_map<MoveOnly, MoveOnly>;
+ using C = std::flat_map<MoveOnly, MoveOnly, std::less<MoveOnly>, KeyContainer<MoveOnly>, ValueContainer<MoveOnly>>;
static_assert(std::is_nothrow_destructible_v<C>);
C c;
}
{
- using V = std::vector<MoveOnly, test_allocator<MoveOnly>>;
- using C = std::flat_map<MoveOnly, MoveOnly, std::less<MoveOnly>, V, V>;
+ using V = KeyContainer<MoveOnly, test_allocator<MoveOnly>>;
+ using V2 = ValueContainer<MoveOnly, test_allocator<MoveOnly>>;
+ using C = std::flat_map<MoveOnly, MoveOnly, std::less<MoveOnly>, V, V2>;
static_assert(std::is_nothrow_destructible_v<C>);
C c;
}
{
- using V = std::deque<MoveOnly, other_allocator<MoveOnly>>;
- using C = std::flat_map<MoveOnly, MoveOnly, std::greater<MoveOnly>, V, V>;
+ using V = KeyContainer<MoveOnly, test_allocator<MoveOnly>>;
+ using V2 = ValueContainer<MoveOnly, test_allocator<MoveOnly>>;
+ using C = std::flat_map<MoveOnly, MoveOnly, std::greater<MoveOnly>, V, V2>;
static_assert(std::is_nothrow_destructible_v<C>);
C c;
}
#if defined(_LIBCPP_VERSION)
{
- using C = std::flat_map<MoveOnly, MoveOnly, ThrowingDtorComp>;
+ using C = std::flat_map<MoveOnly, MoveOnly, ThrowingDtorComp, KeyContainer<MoveOnly>, ValueContainer<MoveOnly>>;
static_assert(!std::is_nothrow_destructible_v<C>);
C c;
}
#endif // _LIBCPP_VERSION
+}
+
+constexpr bool test() {
+ test<std::vector, std::vector>();
+
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque, std::deque>();
+ }
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp
index 7a22746845d00..ae56de816245b 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp
@@ -30,58 +30,13 @@
#include "../../../test_compare.h"
struct DefaultCtableComp {
- explicit DefaultCtableComp() { default_constructed_ = true; }
- bool operator()(int, int) const { return false; }
+ constexpr explicit DefaultCtableComp() { default_constructed_ = true; }
+ constexpr bool operator()(int, int) const { return false; }
bool default_constructed_ = false;
};
-int main(int, char**) {
- {
- // 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_map<int, int, C, V1, V1>;
- using M2 = std::flat_map<int, int, C, V1, V2>;
- using M3 = std::flat_map<int, int, C, V2, V1>;
- using IL = std::initializer_list<std::pair<int, int>>;
- static_assert(std::is_constructible_v<M1, IL, const A1&>);
- static_assert(!std::is_constructible_v<M1, IL, const A2&>);
- static_assert(!std::is_constructible_v<M2, IL, const A2&>);
- static_assert(!std::is_constructible_v<M3, IL, const A2&>);
-
- static_assert(std::is_constructible_v<M1, IL, const C&, const A1&>);
- static_assert(!std::is_constructible_v<M1, IL, const C&, const A2&>);
- static_assert(!std::is_constructible_v<M2, IL, const C&, const A2&>);
- static_assert(!std::is_constructible_v<M3, IL, const C&, const A2&>);
- }
-
- {
- // initializer_list<value_type> needs to match exactly
- using M = std::flat_map<int, short>;
- using C = typename M::key_compare;
- static_assert(std::is_constructible_v<M, std::initializer_list<std::pair<int, short>>>);
- static_assert(std::is_constructible_v<M, std::initializer_list<std::pair<int, short>>, C>);
- static_assert(std::is_constructible_v<M, std::initializer_list<std::pair<int, short>>, C, std::allocator<int>>);
- static_assert(std::is_constructible_v<M, std::initializer_list<std::pair<int, short>>, std::allocator<int>>);
- static_assert(!std::is_constructible_v<M, std::initializer_list<std::pair<const int, short>>>);
- static_assert(!std::is_constructible_v<M, std::initializer_list<std::pair<const int, short>>, C>);
- static_assert(
- !std::is_constructible_v<M, std::initializer_list<std::pair<const int, short>>, C, std::allocator<int>>);
- static_assert(!std::is_constructible_v<M, std::initializer_list<std::pair<const int, short>>, std::allocator<int>>);
- static_assert(!std::is_constructible_v<M, std::initializer_list<std::pair<const int, const short>>>);
- static_assert(!std::is_constructible_v<M, std::initializer_list<std::pair<const int, const short>>, C>);
- static_assert(
- !std::is_constructible_v<M, std::initializer_list<std::pair<const int, const short>>, C, std::allocator<int>>);
- static_assert(
- !std::is_constructible_v<M, std::initializer_list<std::pair<const int, const short>>, std::allocator<int>>);
- }
-
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test() {
std::pair<int, short> expected[] = {{1, 1}, {2, 2}, {3, 3}, {5, 2}};
{
// flat_map(initializer_list<value_type>);
@@ -99,29 +54,27 @@ int main(int, char**) {
}
{
// flat_map(initializer_list<value_type>);
- using M = std::flat_map<int, short, std::greater<int>, std::deque<int, min_allocator<int>>>;
+ using M = std::flat_map<int, short, std::greater<int>, KeyContainer<int, min_allocator<int>>>;
M m = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
}
{
+ // flat_map(initializer_list<value_type>);
+ // different comparator
using A = explicit_allocator<int>;
- {
- // flat_map(initializer_list<value_type>);
- // different comparator
- using M = std::flat_map<int, int, DefaultCtableComp, std::vector<int, A>, std::deque<int, A>>;
- M m = {{1, 1}, {2, 2}, {3, 3}};
- assert(m.size() == 1);
- assert(m.begin()->first == m.begin()->second);
- LIBCPP_ASSERT(*m.begin() == std::make_pair(1, 1));
- assert(m.key_comp().default_constructed_);
- }
- {
- // flat_map(initializer_list<value_type>, const Allocator&);
- using M = std::flat_map<int, int, std::greater<int>, std::deque<int, A>, std::vector<int, A>>;
- A a;
- M m({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, a);
- assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
- }
+ using M = std::flat_map<int, int, DefaultCtableComp, KeyContainer<int, A>, ValueContainer<int, A>>;
+ M m = {{1, 1}, {2, 2}, {3, 3}};
+ assert(m.size() == 1);
+ assert(m.begin()->first == m.begin()->second);
+ assert(m.key_comp().default_constructed_);
+ }
+ {
+ // flat_map(initializer_list<value_type>, const Allocator&);
+ using A = explicit_allocator<int>;
+ using M = std::flat_map<int, int, std::greater<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
+ A a;
+ M m({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, a);
+ assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
}
{
// flat_map(initializer_list<value_type>, const key_compare&);
@@ -136,10 +89,10 @@ int main(int, char**) {
assert(m2 == m);
assert(m2.key_comp() == C(10));
}
- {
+ if (!std::is_constant_evaluated()) {
// 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>>>;
+ using M = std::flat_map<int, short, std::function<bool(int, int)>, KeyContainer<int, min_allocator<int>>>;
auto m = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, std::greater<int>());
assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
assert(m.key_comp()(2, 1) == true);
@@ -147,11 +100,77 @@ int main(int, char**) {
{
// flat_map(initializer_list<value_type> il, const key_compare& comp, const Alloc& a);
using A = explicit_allocator<int>;
- using M = std::flat_map<int, int, std::greater<int>, std::deque<int, A>, std::vector<int, A>>;
+ using M = std::flat_map<int, int, std::greater<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
A a;
M m({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, {}, a);
assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
}
+}
+
+constexpr bool 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_map<int, int, C, V1, V1>;
+ using M2 = std::flat_map<int, int, C, V1, V2>;
+ using M3 = std::flat_map<int, int, C, V2, V1>;
+ using IL = std::initializer_list<std::pair<int, int>>;
+ static_assert(std::is_constructible_v<M1, IL, const A1&>);
+ static_assert(!std::is_constructible_v<M1, IL, const A2&>);
+ static_assert(!std::is_constructible_v<M2, IL, const A2&>);
+ static_assert(!std::is_constructible_v<M3, IL, const A2&>);
+
+ static_assert(std::is_constructible_v<M1, IL, const C&, const A1&>);
+ static_assert(!std::is_constructible_v<M1, IL, const C&, const A2&>);
+ static_assert(!std::is_constructible_v<M2, IL, const C&, const A2&>);
+ static_assert(!std::is_constructible_v<M3, IL, const C&, const A2&>);
+ }
+
+ {
+ // initializer_list<value_type> needs to match exactly
+ using M = std::flat_map<int, short>;
+ using C = typename M::key_compare;
+ static_assert(std::is_constructible_v<M, std::initializer_list<std::pair<int, short>>>);
+ static_assert(std::is_constructible_v<M, std::initializer_list<std::pair<int, short>>, C>);
+ static_assert(std::is_constructible_v<M, std::initializer_list<std::pair<int, short>>, C, std::allocator<int>>);
+ static_assert(std::is_constructible_v<M, std::initializer_list<std::pair<int, short>>, std::allocator<int>>);
+ static_assert(!std::is_constructible_v<M, std::initializer_list<std::pair<const int, short>>>);
+ static_assert(!std::is_constructible_v<M, std::initializer_list<std::pair<const int, short>>, C>);
+ static_assert(
+ !std::is_constructible_v<M, std::initializer_list<std::pair<const int, short>>, C, std::allocator<int>>);
+ static_assert(!std::is_constructible_v<M, std::initializer_list<std::pair<const int, short>>, std::allocator<int>>);
+ static_assert(!std::is_constructible_v<M, std::initializer_list<std::pair<const int, const short>>>);
+ static_assert(!std::is_constructible_v<M, std::initializer_list<std::pair<const int, const short>>, C>);
+ static_assert(
+ !std::is_constructible_v<M, std::initializer_list<std::pair<const int, const short>>, C, std::allocator<int>>);
+ static_assert(
+ !std::is_constructible_v<M, std::initializer_list<std::pair<const int, const short>>, std::allocator<int>>);
+ }
+
+ test<std::vector, std::vector>();
+
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque, std::deque>();
+ }
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp
index 7c0c487969943..812553ea0fa68 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp
@@ -22,51 +22,35 @@
#include <flat_map>
#include <functional>
#include <vector>
+#include <ranges>
+#include "MinSequenceContainer.h"
#include "min_allocator.h"
#include "test_allocator.h"
#include "test_iterators.h"
#include "test_macros.h"
+#include "../helpers.h"
#include "../../../test_compare.h"
-int main(int, char**) {
- {
- // 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_map<int, int, C, V1, V1>;
- using M2 = std::flat_map<int, int, C, V1, V2>;
- using M3 = std::flat_map<int, int, C, V2, V1>;
- using Iter1 = typename M1::iterator;
- using Iter2 = typename M2::iterator;
- using Iter3 = typename M3::iterator;
- static_assert(std::is_constructible_v<M1, Iter1, Iter1, const A1&>);
- static_assert(!std::is_constructible_v<M1, Iter1, Iter1, const A2&>);
- static_assert(!std::is_constructible_v<M2, Iter2, Iter2, const A2&>);
- static_assert(!std::is_constructible_v<M3, Iter3, Iter3, const A2&>);
-
- static_assert(std::is_constructible_v<M1, Iter1, Iter1, const C&, const A1&>);
- static_assert(!std::is_constructible_v<M1, Iter1, Iter1, const C&, const A2&>);
- static_assert(!std::is_constructible_v<M2, Iter2, Iter2, const C&, const A2&>);
- 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}};
+template <class KeyContainer, class ValueContainer>
+constexpr void test() {
+ using Key = typename KeyContainer::value_type;
+ using Value = typename ValueContainer::value_type;
+ using P = std::pair<Key, Value>;
+ P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
{
// flat_map(InputIterator , InputIterator)
// cpp17_input_iterator
- using M = std::flat_map<int, short>;
+ using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
auto m = M(cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 9));
- assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
- LIBCPP_ASSERT(std::ranges::equal(m, expected));
+ assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<Value>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
// explicit(false)
M m2 = {cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 9)};
@@ -75,25 +59,37 @@ int main(int, char**) {
{
// flat_map(InputIterator , InputIterator)
// greater
- using M = std::flat_map<int, short, std::greater<int>, std::deque<int, min_allocator<int>>, std::deque<short>>;
+ using M = std::flat_map<Key, Value, std::greater<Key>, KeyContainer, ValueContainer>;
auto m = M(cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 9));
- assert((m.keys() == std::deque<int, min_allocator<int>>{3, 2, 1}));
- LIBCPP_ASSERT((m.values() == std::deque<short>{6, 4, 1}));
+ assert(std::ranges::equal(m.keys(), KeyContainer{3, 2, 1}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<Value>>{
+ {6, 8, 9},
+ {4, 5, 7},
+ {1, 2, 3},
+ });
}
{
// flat_map(InputIterator , InputIterator)
// Test when the operands are of array type (also contiguous iterator type)
- using M = std::flat_map<int, short, std::greater<int>, std::vector<int, min_allocator<int>>>;
+ using M = std::flat_map<Key, Value, std::greater<Key>, KeyContainer, ValueContainer>;
auto m = M(ar, ar);
assert(m.empty());
}
{
// flat_map(InputIterator , InputIterator, const key_compare&)
- using C = test_less<int>;
- using M = std::flat_map<int, short, C, std::vector<int>, std::deque<short>>;
+ using C = test_less<Key>;
+ using M = std::flat_map<Key, Value, C, KeyContainer, ValueContainer>;
auto m = M(ar, ar + 9, C(3));
- assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
- LIBCPP_ASSERT(std::ranges::equal(m, expected));
+ assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<Value>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
assert(m.key_comp() == C(3));
// explicit(false)
@@ -101,14 +97,27 @@ int main(int, char**) {
assert(m2 == m);
assert(m2.key_comp() == C(3));
}
+}
+
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test_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}};
+
{
// flat_map(InputIterator , InputIterator, const Allocator&)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
- using M = std::flat_map<int, short, std::less<int>, std::vector<int, A1>, std::deque<short, A2>>;
+ using M = std::flat_map<int, short, std::less<int>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
auto m = M(ar, ar + 9, A1(5));
- assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
- LIBCPP_ASSERT(std::ranges::equal(m, expected));
+ assert(std::ranges::equal(m.keys(), KeyContainer<int, A1>{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<short>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
@@ -117,10 +126,16 @@ int main(int, char**) {
// explicit(false)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
- using M = std::flat_map<int, short, std::less<int>, std::vector<int, A1>, std::deque<short, A2>>;
+ using M = std::flat_map<int, short, std::less<int>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
M m = {ar, ar + 9, A1(5)}; // implicit ctor
- assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
- LIBCPP_ASSERT(std::ranges::equal(m, expected));
+ assert(std::ranges::equal(m.keys(), KeyContainer<int, A1>{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<short>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
@@ -129,10 +144,16 @@ int main(int, char**) {
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
- using M = std::flat_map<int, short, C, std::vector<int, A1>, std::deque<short, A2>>;
+ using M = std::flat_map<int, short, C, KeyContainer<int, A1>, ValueContainer<short, A2>>;
auto m = M(ar, ar + 9, C(3), A1(5));
- assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
- LIBCPP_ASSERT(std::ranges::equal(m, expected));
+ assert(std::ranges::equal(m.keys(), KeyContainer<int, A1>{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<short>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
assert(m.key_comp() == C(3));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
@@ -142,13 +163,73 @@ int main(int, char**) {
// explicit(false)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
- using M = std::flat_map<int, short, std::less<int>, std::deque<int, A1>, std::vector<short, A2>>;
+ using M = std::flat_map<int, short, std::less<int>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
M m = {ar, ar + 9, {}, A2(5)}; // implicit ctor
- assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
- LIBCPP_ASSERT(std::ranges::equal(m, expected));
+ assert(std::ranges::equal(m.keys(), KeyContainer<int, A1>{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<short>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
+}
+
+constexpr bool 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_map<int, int, C, V1, V1>;
+ using M2 = std::flat_map<int, int, C, V1, V2>;
+ using M3 = std::flat_map<int, int, C, V2, V1>;
+ using Iter1 = typename M1::iterator;
+ using Iter2 = typename M2::iterator;
+ using Iter3 = typename M3::iterator;
+ static_assert(std::is_constructible_v<M1, Iter1, Iter1, const A1&>);
+ static_assert(!std::is_constructible_v<M1, Iter1, Iter1, const A2&>);
+ static_assert(!std::is_constructible_v<M2, Iter2, Iter2, const A2&>);
+ static_assert(!std::is_constructible_v<M3, Iter3, Iter3, const A2&>);
+
+ static_assert(std::is_constructible_v<M1, Iter1, Iter1, const C&, const A1&>);
+ static_assert(!std::is_constructible_v<M1, Iter1, Iter1, const C&, const A2&>);
+ static_assert(!std::is_constructible_v<M2, Iter2, Iter2, const C&, const A2&>);
+ static_assert(!std::is_constructible_v<M3, Iter3, Iter3, const C&, const A2&>);
+ }
+
+ test<std::vector<int>, std::vector<int>>();
+ test<std::vector<int>, std::vector<double>>();
+ test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
+ test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
+ test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
+
+ test_alloc<std::vector, std::vector>();
+
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ test_alloc<std::deque, std::deque>();
+ }
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move.pass.cpp
index 955d3156064aa..091f727730321 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move.pass.cpp
@@ -16,6 +16,7 @@
#include <deque>
#include <flat_map>
#include <functional>
+#include <type_traits>
#include <utility>
#include <vector>
@@ -25,11 +26,12 @@
#include "test_allocator.h"
#include "min_allocator.h"
-int main(int, char**) {
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test() {
{
using C = test_less<int>;
using A = test_allocator<int>;
- using M = std::flat_map<int, int, C, std::vector<int, A>, std::deque<int, A>>;
+ using M = std::flat_map<int, int, C, KeyContainer<int, A>, ValueContainer<int, A>>;
M mo = M({{1, 1}, {2, 2}, {3, 1}}, C(5), A(7));
M m = std::move(mo);
assert((m == M{{1, 1}, {2, 2}, {3, 1}}));
@@ -45,7 +47,7 @@ int main(int, char**) {
{
using C = test_less<int>;
using A = min_allocator<int>;
- using M = std::flat_map<int, int, C, std::vector<int, A>, std::deque<int, A>>;
+ using M = std::flat_map<int, int, C, KeyContainer<int, A>, ValueContainer<int, A>>;
M mo = M({{1, 1}, {2, 2}, {3, 1}}, C(5), A());
M m = std::move(mo);
assert((m == M{{1, 1}, {2, 2}, {3, 1}}));
@@ -58,9 +60,9 @@ int main(int, char**) {
assert(m.keys().get_allocator() == A());
assert(m.values().get_allocator() == A());
}
- {
+ if (!std::is_constant_evaluated()) {
// A moved-from flat_map maintains its class invariant in the presence of moved-from comparators.
- using M = std::flat_map<int, int, std::function<bool(int, int)>>;
+ using M = std::flat_map<int, int, std::function<bool(int, int)>, KeyContainer<int>, ValueContainer<int>>;
M mo = M({{1, 1}, {2, 2}, {3, 1}}, std::less<int>());
M m = std::move(mo);
assert(m.size() == 3);
@@ -75,7 +77,7 @@ int main(int, char**) {
}
{
// moved-from object maintains invariant if one of underlying container does not clear after move
- using M = std::flat_map<int, int, std::less<>, std::vector<int>, CopyOnlyVector<int>>;
+ using M = std::flat_map<int, int, std::less<>, KeyContainer<int>, CopyOnlyVector<int>>;
M m1 = M({1, 2, 3}, {1, 2, 3});
M m2 = std::move(m1);
assert(m2.size() == 3);
@@ -84,5 +86,26 @@ int main(int, char**) {
LIBCPP_ASSERT(m1.keys().size() == 0);
LIBCPP_ASSERT(m1.values().size() == 0);
}
+}
+
+constexpr bool test() {
+ test<std::vector, std::vector>();
+
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque, std::deque>();
+ }
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_alloc.pass.cpp
index 93a3976422520..caec240ccee3b 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_alloc.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_alloc.pass.cpp
@@ -24,30 +24,13 @@
#include "../../../test_compare.h"
#include "test_allocator.h"
-int main(int, char**) {
- {
- // 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_map<int, int, C, V1, V1>;
- using M2 = std::flat_map<int, int, C, V1, V2>;
- using M3 = std::flat_map<int, int, C, V2, V1>;
- static_assert(std::is_constructible_v<M1, M1&&, const A1&>);
- static_assert(!std::is_constructible_v<M1, M1&&, const A2&>);
- static_assert(!std::is_constructible_v<M2, M2&&, const A2&>);
- static_assert(!std::is_constructible_v<M3, M3&&, const A2&>);
- }
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test() {
{
std::pair<int, int> expected[] = {{1, 1}, {2, 2}, {3, 1}};
using C = test_less<int>;
using A = test_allocator<int>;
- using M = std::flat_map<int, int, C, std::vector<int, A>, std::deque<int, A>>;
+ using M = std::flat_map<int, int, C, KeyContainer<int, A>, ValueContainer<int, A>>;
auto mo = M(expected, expected + 3, C(5), A(7));
auto m = M(std::move(mo), A(3));
@@ -68,7 +51,7 @@ int main(int, char**) {
}
{
// moved-from object maintains invariant if one of underlying container does not clear after move
- using M = std::flat_map<int, int, std::less<>, std::vector<int>, CopyOnlyVector<int>>;
+ using M = std::flat_map<int, int, std::less<>, KeyContainer<int>, CopyOnlyVector<int>>;
M m1 = M({1, 2, 3}, {1, 2, 3});
M m2(std::move(m1), std::allocator<int>{});
assert(m2.size() == 3);
@@ -77,6 +60,45 @@ int main(int, char**) {
LIBCPP_ASSERT(m1.keys().size() == 0);
LIBCPP_ASSERT(m1.values().size() == 0);
}
+}
+
+constexpr bool 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_map<int, int, C, V1, V1>;
+ using M2 = std::flat_map<int, int, C, V1, V2>;
+ using M3 = std::flat_map<int, int, C, V2, V1>;
+ static_assert(std::is_constructible_v<M1, M1&&, const A1&>);
+ static_assert(!std::is_constructible_v<M1, M1&&, const A2&>);
+ static_assert(!std::is_constructible_v<M2, M2&&, const A2&>);
+ static_assert(!std::is_constructible_v<M3, M3&&, const A2&>);
+ }
+
+ test<std::vector, std::vector>();
+
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque, std::deque>();
+ }
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp
index a94c442c695dd..aa2eadf2f06e2 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp
@@ -26,12 +26,13 @@
#include "test_allocator.h"
#include "min_allocator.h"
-int main(int, char**) {
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test() {
{
using C = test_less<int>;
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>>;
+ using M = std::flat_map<int, char, C, KeyContainer<int, A1>, ValueContainer<char, A2>>;
M mo = M({{1, 1}, {2, 3}, {3, 2}}, C(5), A1(7));
M m = M({}, C(3), A1(7));
m = std::move(mo);
@@ -46,7 +47,7 @@ int main(int, char**) {
using C = test_less<int>;
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>>;
+ using M = std::flat_map<int, char, C, KeyContainer<int, A1>, ValueContainer<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 = std::move(mo);
@@ -59,7 +60,7 @@ int main(int, char**) {
}
{
using A = min_allocator<int>;
- using M = std::flat_map<int, int, std::greater<int>, std::vector<int, A>, std::vector<int, A>>;
+ using M = std::flat_map<int, int, std::greater<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
M mo = M({{5, 1}, {4, 2}, {3, 3}}, A());
M m = M({{4, 4}, {3, 3}, {2, 2}, {1, 1}}, A());
m = std::move(mo);
@@ -69,6 +70,26 @@ int main(int, char**) {
assert(vs.get_allocator() == A());
assert(mo.empty());
}
+}
- return 0;
+constexpr bool test() {
+ test<std::vector, std::vector>();
+
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque, std::deque>();
+ }
+
+ return true;
}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
+ return 0;
+}
\ No newline at end of file
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign_clears.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign_clears.pass.cpp
index f28d52dd4e463..ddedb0c015706 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign_clears.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign_clears.pass.cpp
@@ -16,6 +16,7 @@
#include <algorithm>
#include <cassert>
#include <compare>
+#include <deque>
#include <flat_map>
#include <functional>
#include <utility>
@@ -27,9 +28,9 @@
struct MoveNegates {
int value_ = 0;
MoveNegates() = default;
- MoveNegates(int v) : value_(v) {}
- MoveNegates(MoveNegates&& rhs) : value_(rhs.value_) { rhs.value_ = -rhs.value_; }
- MoveNegates& operator=(MoveNegates&& rhs) {
+ constexpr MoveNegates(int v) : value_(v) {}
+ constexpr MoveNegates(MoveNegates&& rhs) : value_(rhs.value_) { rhs.value_ = -rhs.value_; }
+ constexpr MoveNegates& operator=(MoveNegates&& rhs) {
value_ = rhs.value_;
rhs.value_ = -rhs.value_;
return *this;
@@ -41,9 +42,9 @@ struct MoveNegates {
struct MoveClears {
int value_ = 0;
MoveClears() = default;
- MoveClears(int v) : value_(v) {}
- MoveClears(MoveClears&& rhs) : value_(rhs.value_) { rhs.value_ = 0; }
- MoveClears& operator=(MoveClears&& rhs) {
+ constexpr MoveClears(int v) : value_(v) {}
+ constexpr MoveClears(MoveClears&& rhs) : value_(rhs.value_) { rhs.value_ = 0; }
+ constexpr MoveClears& operator=(MoveClears&& rhs) {
value_ = rhs.value_;
rhs.value_ = 0;
return *this;
@@ -52,11 +53,12 @@ struct MoveClears {
auto operator<=>(const MoveClears&) const = default;
};
-int main(int, char**) {
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test() {
auto value_eq = [](auto&& p, auto&& q) { return p.first == q.first; };
{
const std::pair<int, int> expected[] = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}};
- using M = std::flat_map<MoveNegates, int, std::less<MoveNegates>, std::vector<MoveNegates>>;
+ using M = std::flat_map<MoveNegates, int, std::less<MoveNegates>, KeyContainer<MoveNegates>, ValueContainer<int>>;
M m = M(expected, expected + 8);
M m2 = M(expected, expected + 3);
@@ -73,7 +75,7 @@ int main(int, char**) {
}
{
const std::pair<int, int> expected[] = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}};
- using M = std::flat_map<MoveClears, int, std::less<MoveClears>, std::vector<MoveClears>>;
+ using M = std::flat_map<MoveClears, int, std::less<MoveClears>, KeyContainer<MoveClears>, ValueContainer<int>>;
M m = M(expected, expected + 8);
M m2 = M(expected, expected + 3);
@@ -90,7 +92,7 @@ int main(int, char**) {
}
{
// moved-from object maintains invariant if one of underlying container does not clear after move
- using M = std::flat_map<int, int, std::less<>, std::vector<int>, CopyOnlyVector<int>>;
+ using M = std::flat_map<int, int, std::less<>, KeyContainer<int>, CopyOnlyVector<int>>;
M m1 = M({1, 2, 3}, {1, 2, 3});
M m2 = M({1, 2}, {1, 2});
m2 = std::move(m1);
@@ -100,5 +102,26 @@ int main(int, char**) {
LIBCPP_ASSERT(m1.keys().size() == 0);
LIBCPP_ASSERT(m1.values().size() == 0);
}
+}
+
+constexpr bool test() {
+ test<std::vector, std::vector>();
+
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque, std::deque>();
+ }
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign_noexcept.compile.pass.cpp
similarity index 99%
rename from libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign_noexcept.pass.cpp
rename to libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign_noexcept.compile.pass.cpp
index 665b763e6c4f7..18d332cf27b5b 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign_noexcept.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign_noexcept.compile.pass.cpp
@@ -49,7 +49,7 @@ struct MoveThrowsComp {
bool operator()(const auto&, const auto&) const;
};
-int main(int, char**) {
+void test() {
{
using C = std::flat_map<int, int>;
LIBCPP_STATIC_ASSERT(std::is_nothrow_move_assignable_v<C>);
@@ -105,6 +105,4 @@ int main(int, char**) {
using C = std::flat_map<int, int, std::less<int>, std::vector<int>, std::pmr::vector<int>>;
static_assert(!std::is_nothrow_move_assignable_v<C>);
}
-
- return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp
index 282cc71f31994..ae447f62b57d4 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp
@@ -27,9 +27,11 @@
#include <vector>
#include "min_allocator.h"
+#include "MinSequenceContainer.h"
#include "test_allocator.h"
#include "test_iterators.h"
#include "test_macros.h"
+#include "../helpers.h"
#include "../../../test_compare.h"
// test constraint container-compatible-range
@@ -66,70 +68,28 @@ static_assert(std::is_constructible_v<Map,
static_assert(!std::is_constructible_v<Map, std::from_range_t, RangeOf<int>, std::less<int>, std::allocator<int>>);
static_assert(!std::is_constructible_v<Map, std::from_range_t, RangeOf<double>, std::less<int>, std::allocator<int>>);
-int main(int, char**) {
- {
- // 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_map<int, int, C, V1, V1>;
- using M2 = std::flat_map<int, int, C, V1, V2>;
- using M3 = std::flat_map<int, int, C, V2, V1>;
- static_assert(std::is_constructible_v<M1, std::from_range_t, M1, const A1&>);
- static_assert(!std::is_constructible_v<M1, std::from_range_t, M1, const A2&>);
- static_assert(!std::is_constructible_v<M2, std::from_range_t, M2, const A2&>);
- static_assert(!std::is_constructible_v<M3, std::from_range_t, M3, const A2&>);
-
- static_assert(std::is_constructible_v<M1, std::from_range_t, M1, const C&, const A1&>);
- static_assert(!std::is_constructible_v<M1, std::from_range_t, M1, const C&, const A2&>);
- static_assert(!std::is_constructible_v<M2, std::from_range_t, M2, const C&, const A2&>);
- static_assert(!std::is_constructible_v<M3, std::from_range_t, M3, const C&, const A2&>);
- }
- {
- // container-compatible-range
- using C = test_less<int>;
- using A1 = test_allocator<int>;
- using A2 = test_allocator<std::string>;
- using M = std::flat_map<int, std::string, C, std::vector<int, A1>, std::vector<std::string, A2>>;
- using Pair = std::pair<int, std::string>;
- using PairLike = std::tuple<int, std::string>;
- using NonPairLike = int;
-
- static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<Pair>&>);
- static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<PairLike>&>);
- static_assert(!std::is_constructible_v<M, std::from_range_t, std::vector<NonPairLike>&>);
-
- static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<Pair>&, const C&>);
- static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<PairLike>&, const C&>);
- static_assert(!std::is_constructible_v<M, std::from_range_t, std::vector<NonPairLike>&, const C&>);
-
- static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<Pair>&, const A1&>);
- static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<PairLike>&, const A1&>);
- static_assert(!std::is_constructible_v<M, std::from_range_t, std::vector<NonPairLike>&, const A1&>);
-
- static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<Pair>&, const C&, const A1&>);
- static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<PairLike>&, const C&, const A1&>);
- 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}};
+template <class KeyContainer, class ValueContainer>
+constexpr void test() {
+ using Key = typename KeyContainer::value_type;
+ using Value = typename ValueContainer::value_type;
+ using P = std::pair<Key, Value>;
+ P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
{
// flat_map(from_range_t, R&&)
// input_range && !common
- using M = std::flat_map<int, short>;
+ using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
using Iter = cpp20_input_iterator<const P*>;
using Sent = sentinel_wrapper<Iter>;
using R = std::ranges::subrange<Iter, Sent>;
auto m = M(std::from_range, R(Iter(ar), Sent(Iter(ar + 9))));
- assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
- LIBCPP_ASSERT(std::ranges::equal(m, expected));
+ assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<Value>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
// explicit(false)
M m2 = {std::from_range, R(Iter(ar), Sent(Iter(ar + 9)))};
@@ -138,31 +98,49 @@ int main(int, char**) {
{
// flat_map(from_range_t, R&&)
// greater
- using M = std::flat_map<int, short, std::greater<int>, std::deque<int, min_allocator<int>>, std::deque<short>>;
+ using M = std::flat_map<Key, Value, std::greater<int>, KeyContainer, ValueContainer>;
using Iter = cpp20_input_iterator<const P*>;
using Sent = sentinel_wrapper<Iter>;
using R = std::ranges::subrange<Iter, Sent>;
auto m = M(std::from_range, R(Iter(ar), Sent(Iter(ar + 9))));
- assert((m.keys() == std::deque<int, min_allocator<int>>{3, 2, 1}));
- LIBCPP_ASSERT((m.values() == std::deque<short>{6, 4, 1}));
+ assert(std::ranges::equal(m.keys(), KeyContainer{3, 2, 1}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<Value>>{
+ {6, 8, 9},
+ {4, 5, 7},
+ {1, 2, 3},
+ });
}
{
// flat_map(from_range_t, R&&)
// contiguous range
- using M = std::flat_map<int, short>;
+ using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
using R = std::ranges::subrange<const P*>;
auto m = M(std::from_range, R(ar, ar + 9));
- assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
- LIBCPP_ASSERT(std::ranges::equal(m, expected));
+ assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<Value>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
}
{
// flat_map(from_range_t, R&&, const key_compare&)
using C = test_less<int>;
- using M = std::flat_map<int, short, C, std::vector<int>, std::deque<short>>;
+ using M = std::flat_map<Key, Value, C, KeyContainer, ValueContainer>;
using R = std::ranges::subrange<const P*>;
auto m = M(std::from_range, R(ar, ar + 9), C(3));
- assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
- LIBCPP_ASSERT(std::ranges::equal(m, expected));
+ assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<Value>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
assert(m.key_comp() == C(3));
// explicit(false)
@@ -170,15 +148,27 @@ int main(int, char**) {
assert(m2 == m);
assert(m2.key_comp() == C(3));
}
+}
+
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test_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}};
{
// flat_map(from_range_t, R&&, const Allocator&)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
- using M = std::flat_map<int, short, std::less<int>, std::vector<int, A1>, std::deque<short, A2>>;
+ using M = std::flat_map<int, short, std::less<int>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
using R = std::ranges::subrange<const P*>;
auto m = M(std::from_range, R(ar, ar + 9), A1(5));
- assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
- LIBCPP_ASSERT(std::ranges::equal(m, expected));
+ assert(std::ranges::equal(m.keys(), KeyContainer<int, A1>{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<short>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
@@ -187,11 +177,17 @@ int main(int, char**) {
// explicit(false)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
- using M = std::flat_map<int, short, std::less<int>, std::vector<int, A1>, std::deque<short, A2>>;
+ using M = std::flat_map<int, short, std::less<int>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
using R = std::ranges::subrange<const P*>;
M m = {std::from_range, R(ar, ar + 9), A1(5)}; // implicit ctor
- assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
- LIBCPP_ASSERT(std::ranges::equal(m, expected));
+ assert(std::ranges::equal(m.keys(), KeyContainer<int, A1>{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<short>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
@@ -200,11 +196,17 @@ int main(int, char**) {
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
- using M = std::flat_map<int, short, C, std::vector<int, A1>, std::deque<short, A2>>;
+ using M = std::flat_map<int, short, C, KeyContainer<int, A1>, ValueContainer<short, A2>>;
using R = std::ranges::subrange<const P*>;
auto m = M(std::from_range, R(ar, ar + 9), C(3), A1(5));
- assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
- LIBCPP_ASSERT(std::ranges::equal(m, expected));
+ assert(std::ranges::equal(m.keys(), KeyContainer<int, A1>{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<short>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
assert(m.key_comp() == C(3));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
@@ -214,14 +216,97 @@ int main(int, char**) {
// explicit(false)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
- using M = std::flat_map<int, short, std::less<int>, std::deque<int, A1>, std::vector<short, A2>>;
+ using M = std::flat_map<int, short, std::less<int>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
using R = std::ranges::subrange<const P*>;
M m = {std::from_range, R(ar, ar + 9), {}, A2(5)}; // implicit ctor
- assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
- LIBCPP_ASSERT(std::ranges::equal(m, expected));
+ assert(std::ranges::equal(m.keys(), KeyContainer<int, A1>{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<short>>{
+ {1, 2, 3},
+ {4, 5, 7},
+ {6, 8, 9},
+ });
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
+}
+
+constexpr bool 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_map<int, int, C, V1, V1>;
+ using M2 = std::flat_map<int, int, C, V1, V2>;
+ using M3 = std::flat_map<int, int, C, V2, V1>;
+ static_assert(std::is_constructible_v<M1, std::from_range_t, M1, const A1&>);
+ static_assert(!std::is_constructible_v<M1, std::from_range_t, M1, const A2&>);
+ static_assert(!std::is_constructible_v<M2, std::from_range_t, M2, const A2&>);
+ static_assert(!std::is_constructible_v<M3, std::from_range_t, M3, const A2&>);
+
+ static_assert(std::is_constructible_v<M1, std::from_range_t, M1, const C&, const A1&>);
+ static_assert(!std::is_constructible_v<M1, std::from_range_t, M1, const C&, const A2&>);
+ static_assert(!std::is_constructible_v<M2, std::from_range_t, M2, const C&, const A2&>);
+ static_assert(!std::is_constructible_v<M3, std::from_range_t, M3, const C&, const A2&>);
+ }
+ {
+ // container-compatible-range
+ using C = test_less<int>;
+ using A1 = test_allocator<int>;
+ using A2 = test_allocator<std::string>;
+ using M = std::flat_map<int, std::string, C, std::vector<int, A1>, std::vector<std::string, A2>>;
+ using Pair = std::pair<int, std::string>;
+ using PairLike = std::tuple<int, std::string>;
+ using NonPairLike = int;
+
+ static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<Pair>&>);
+ static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<PairLike>&>);
+ static_assert(!std::is_constructible_v<M, std::from_range_t, std::vector<NonPairLike>&>);
+
+ static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<Pair>&, const C&>);
+ static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<PairLike>&, const C&>);
+ static_assert(!std::is_constructible_v<M, std::from_range_t, std::vector<NonPairLike>&, const C&>);
+
+ static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<Pair>&, const A1&>);
+ static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<PairLike>&, const A1&>);
+ static_assert(!std::is_constructible_v<M, std::from_range_t, std::vector<NonPairLike>&, const A1&>);
+
+ static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<Pair>&, const C&, const A1&>);
+ static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<PairLike>&, const C&, const A1&>);
+ static_assert(!std::is_constructible_v<M, std::from_range_t, std::vector<NonPairLike>&, const C&, const A1&>);
+ }
+
+ test<std::vector<int>, std::vector<int>>();
+ test<std::vector<int>, std::vector<double>>();
+ test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
+ test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
+ test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
+
+ test_alloc<std::vector, std::vector>();
+
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ test_alloc<std::deque, std::deque>();
+ }
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp
index 3c8868f2ff424..698f667c896ab 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp
@@ -31,39 +31,18 @@
#include "test_allocator.h"
#include "test_iterators.h"
#include "test_macros.h"
+#include "../helpers.h"
#include "../../../test_compare.h"
-int main(int, char**) {
- {
- // 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_map<int, int, C, V1, V1>;
- using M2 = std::flat_map<int, int, C, V1, V2>;
- using M3 = std::flat_map<int, int, C, V2, V1>;
- static_assert(std::is_constructible_v<M1, std::sorted_unique_t, const V1&, const V1&, const A1&>);
- static_assert(!std::is_constructible_v<M1, std::sorted_unique_t, const V1&, const V1&, const A2&>);
- static_assert(!std::is_constructible_v<M2, std::sorted_unique_t, const V1&, const V2&, const A2&>);
- static_assert(!std::is_constructible_v<M3, std::sorted_unique_t, const V2&, const V1&, const A2&>);
-
- static_assert(std::is_constructible_v<M1, std::sorted_unique_t, const V1&, const V1&, const C&, const A1&>);
- static_assert(!std::is_constructible_v<M1, std::sorted_unique_t, const V1&, const V1&, const C&, const A2&>);
- static_assert(!std::is_constructible_v<M2, std::sorted_unique_t, const V1&, const V2&, const C&, const A2&>);
- static_assert(!std::is_constructible_v<M3, std::sorted_unique_t, const V2&, const V1&, const C&, const A2&>);
- }
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test() {
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type)
- using M = std::flat_map<int, char>;
- std::vector<int> ks = {1, 2, 4, 10};
- std::vector<char> vs = {4, 3, 2, 1};
- auto ks2 = ks;
- auto vs2 = vs;
+ using M = std::flat_map<int, char, std::less<int>, KeyContainer<int>, ValueContainer<char>>;
+ KeyContainer<int> ks = {1, 2, 4, 10};
+ ValueContainer<char> vs = {4, 3, 2, 1};
+ auto ks2 = ks;
+ auto vs2 = vs;
auto m = M(std::sorted_unique, ks, vs);
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
@@ -79,8 +58,8 @@ int main(int, char**) {
{
// flat_map(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_map<int, char, std::greater<int>, Ks, Vs>;
Ks ks = {10, 4, 2, 1};
Vs vs = {1, 2, 3, 4};
@@ -95,9 +74,9 @@ int main(int, char**) {
// flat_map(sorted_unique_t, key_container_type , mapped_container_type)
// allocator copied into the containers
using A = test_allocator<int>;
- using M = std::flat_map<int, int, std::less<int>, std::vector<int, A>, std::deque<int, A>>;
- auto ks = std::vector<int, A>({1, 2, 4, 10}, A(4));
- auto vs = std::deque<int, A>({4, 3, 2, 1}, A(5));
+ using M = std::flat_map<int, int, std::less<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
+ auto ks = KeyContainer<int, A>({1, 2, 4, 10}, A(4));
+ auto vs = ValueContainer<int, A>({4, 3, 2, 1}, A(5));
auto 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
@@ -107,10 +86,10 @@ int main(int, char**) {
}
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type, key_compare)
- using C = test_less<int>;
- using M = std::flat_map<int, char, C>;
- std::vector<int> ks = {1, 2, 4, 10};
- std::vector<char> vs = {4, 3, 2, 1};
+ using C = test_less<int>;
+ using M = std::flat_map<int, char, C, KeyContainer<int>, ValueContainer<char>>;
+ KeyContainer<int> ks = {1, 2, 4, 10};
+ ValueContainer<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}}));
@@ -123,12 +102,12 @@ int main(int, char**) {
}
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type, key_compare, const Allocator&)
- using C = test_less<int>;
- using A = test_allocator<int>;
- using M = std::flat_map<int, int, C, std::vector<int, A>, std::vector<int, A>>;
- std::vector<int, A> ks = {1, 2, 4, 10};
- std::vector<int, A> vs = {4, 3, 2, 1};
- auto m = M(std::sorted_unique, ks, vs, C(4), A(5));
+ using C = test_less<int>;
+ using A = test_allocator<int>;
+ using M = std::flat_map<int, int, C, KeyContainer<int, A>, ValueContainer<int, A>>;
+ KeyContainer<int, A> ks = {1, 2, 4, 10};
+ ValueContainer<int, A> vs = {4, 3, 2, 1};
+ auto m = M(std::sorted_unique, ks, vs, C(4), A(5));
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert(m.key_comp() == C(4));
assert(m.keys().get_allocator() == A(5));
@@ -144,9 +123,9 @@ int main(int, char**) {
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type, const Allocator&)
using A = test_allocator<int>;
- using M = std::flat_map<int, int, std::less<int>, std::vector<int, A>, std::deque<int, A>>;
- auto ks = std::vector<int, A>({1, 2, 4, 10}, A(4));
- auto vs = std::deque<int, A>({4, 3, 2, 1}, A(5));
+ using M = std::flat_map<int, int, std::less<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
+ auto ks = KeyContainer<int, A>({1, 2, 4, 10}, A(4));
+ auto vs = ValueContainer<int, A>({4, 3, 2, 1}, A(5));
auto m = M(std::sorted_unique, ks, vs, A(6)); // replaces the allocators
assert(!ks.empty()); // it was an lvalue above
assert(!vs.empty()); // it was an lvalue above
@@ -160,6 +139,51 @@ int main(int, char**) {
assert(m2.keys().get_allocator() == A(6));
assert(m2.values().get_allocator() == A(6));
}
+}
+
+constexpr bool 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_map<int, int, C, V1, V1>;
+ using M2 = std::flat_map<int, int, C, V1, V2>;
+ using M3 = std::flat_map<int, int, C, V2, V1>;
+ static_assert(std::is_constructible_v<M1, std::sorted_unique_t, const V1&, const V1&, const A1&>);
+ static_assert(!std::is_constructible_v<M1, std::sorted_unique_t, const V1&, const V1&, const A2&>);
+ static_assert(!std::is_constructible_v<M2, std::sorted_unique_t, const V1&, const V2&, const A2&>);
+ static_assert(!std::is_constructible_v<M3, std::sorted_unique_t, const V2&, const V1&, const A2&>);
+
+ static_assert(std::is_constructible_v<M1, std::sorted_unique_t, const V1&, const V1&, const C&, const A1&>);
+ static_assert(!std::is_constructible_v<M1, std::sorted_unique_t, const V1&, const V1&, const C&, const A2&>);
+ static_assert(!std::is_constructible_v<M2, std::sorted_unique_t, const V1&, const V2&, const C&, const A2&>);
+ static_assert(!std::is_constructible_v<M3, std::sorted_unique_t, const V2&, const V1&, const C&, const A2&>);
+ }
+
+ test<std::vector, std::vector>();
+
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque, std::vector>();
+ test<std::deque, std::deque>();
+ }
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_initializer_list.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_initializer_list.pass.cpp
index 26452472ba201..8f00e04f84d12 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_initializer_list.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_initializer_list.pass.cpp
@@ -22,6 +22,7 @@
#include <deque>
#include <flat_map>
#include <functional>
+#include <type_traits>
#include <vector>
#include "min_allocator.h"
@@ -31,13 +32,87 @@
#include "../../../test_compare.h"
template <class T, class U>
-std::initializer_list<std::pair<T, U>> il = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
+constexpr std::initializer_list<std::pair<T, U>> il = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
-const auto il1 = il<int, int>;
-const auto il2 = il<int, short>;
-const auto il3 = il<short, int>;
+constexpr auto il1 = il<int, int>;
+constexpr auto il2 = il<int, short>;
+constexpr auto il3 = il<short, int>;
-int main(int, char**) {
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test() {
+ {
+ // flat_map(sorted_unique_t, initializer_list<value_type>);
+ using M = std::flat_map<int, int, std::less<int>, KeyContainer<int>, ValueContainer<int>>;
+ auto m = M(std::sorted_unique, il1);
+ auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
+ assert(m == expected);
+
+ // explicit(false)
+ M m2 = {std::sorted_unique, il1};
+ assert(m2 == m);
+ }
+ if (!std::is_constant_evaluated()) {
+ // flat_map(sorted_unique_t, initializer_list<value_type>, const key_compare&);
+ using M = std::flat_map<int, int, std::function<bool(int, int)>, KeyContainer<int>, ValueContainer<int>>;
+ auto m = M(std::sorted_unique, il1, std::less<int>());
+ assert(m == M({{1, 1}, {2, 2}, {4, 4}, {5, 5}}, std::less<>()));
+ assert(m.key_comp()(1, 2) == true);
+
+ // explicit(false)
+ M m2 = {std::sorted_unique, il1, std::less<int>()};
+ assert(m2 == m);
+ }
+ {
+ // flat_map(sorted_unique_t, initializer_list<value_type>, const key_compare&);
+ // greater
+ using M = std::flat_map<int, int, std::greater<int>, KeyContainer<int, min_allocator<int>>, ValueContainer<int>>;
+ std::initializer_list<std::pair<int, int>> il4{{5, 5}, {4, 4}, {2, 2}, {1, 1}};
+ auto m = M(std::sorted_unique, il4, std::greater<int>());
+ assert((m == M{{5, 5}, {4, 4}, {2, 2}, {1, 1}}));
+ }
+ {
+ // flat_map(sorted_unique_t, initializer_list<value_type>, const Allocator&)
+ using A1 = test_allocator<int>;
+ using A2 = test_allocator<short>;
+ using M = std::flat_map<int, short, std::less<int>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
+ auto m = M(std::sorted_unique, il2, A1(5));
+ auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
+ assert(m == expected);
+ assert(m.keys().get_allocator() == A1(5));
+ assert(m.values().get_allocator() == A2(5));
+
+ // explicit(false)
+ M m2 = {std::sorted_unique, il2, A1(5)};
+ assert(m2 == m);
+ assert(m2.keys().get_allocator() == A1(5));
+ assert(m2.values().get_allocator() == A2(5));
+ }
+ {
+ // flat_map(sorted_unique_t, initializer_list<value_type>, const key_compare&, const Allocator&);
+ using C = test_less<int>;
+ using A1 = test_allocator<int>;
+ using A2 = test_allocator<short>;
+ using M = std::flat_map<int, short, C, KeyContainer<int, A1>, ValueContainer<short, A2>>;
+ auto m = M(std::sorted_unique, il2, C(3), A1(5));
+ assert((m == M{{1, 1}, {2, 2}, {4, 4}, {5, 5}}));
+ assert(m.key_comp() == C(3));
+ assert(m.keys().get_allocator() == A1(5));
+ assert(m.values().get_allocator() == A2(5));
+ }
+ {
+ // flat_map(sorted_unique_t, initializer_list<value_type>, const key_compare&, const Allocator&);
+ // explicit(false)
+ using A1 = test_allocator<short>;
+ using A2 = test_allocator<int>;
+ using M = std::flat_map<short, int, std::less<int>, KeyContainer<short, A1>, ValueContainer<int, A2>>;
+ M m = {std::sorted_unique, il3, {}, A1(5)}; // implicit ctor
+ assert((m == M{{1, 1}, {2, 2}, {4, 4}, {5, 5}}));
+ assert(m.keys().get_allocator() == A1(5));
+ assert(m.values().get_allocator() == A2(5));
+ }
+}
+
+constexpr bool test() {
{
// The constructors in this subclause shall not participate in overload
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
@@ -104,76 +179,23 @@ int main(int, char**) {
std::allocator<int>>);
}
- {
- // flat_map(sorted_unique_t, initializer_list<value_type>);
- using M = std::flat_map<int, int>;
- auto m = M(std::sorted_unique, il1);
- auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
- assert(m == expected);
-
- // explicit(false)
- M m2 = {std::sorted_unique, il1};
- assert(m2 == m);
- }
- {
- // flat_map(sorted_unique_t, initializer_list<value_type>, const key_compare&);
- using M = std::flat_map<int, int, std::function<bool(int, int)>>;
- auto m = M(std::sorted_unique, il1, std::less<int>());
- assert(m == M({{1, 1}, {2, 2}, {4, 4}, {5, 5}}, std::less<>()));
- assert(m.key_comp()(1, 2) == true);
+ test<std::vector, std::vector>();
- // explicit(false)
- M m2 = {std::sorted_unique, il1, std::less<int>()};
- assert(m2 == m);
- }
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
{
- // flat_map(sorted_unique_t, initializer_list<value_type>, const key_compare&);
- // greater
- using M = std::flat_map<int, int, std::greater<int>, std::deque<int, min_allocator<int>>, std::vector<int>>;
- std::initializer_list<std::pair<int, int>> il4{{5, 5}, {4, 4}, {2, 2}, {1, 1}};
- auto m = M(std::sorted_unique, il4, std::greater<int>());
- assert((m == M{{5, 5}, {4, 4}, {2, 2}, {1, 1}}));
+ test<std::deque, std::deque>();
}
- {
- // flat_map(sorted_unique_t, initializer_list<value_type>, const Allocator&)
- using A1 = test_allocator<int>;
- using A2 = test_allocator<short>;
- using M = std::flat_map<int, short, std::less<int>, std::vector<int, A1>, std::deque<short, A2>>;
- auto m = M(std::sorted_unique, il2, A1(5));
- auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
- assert(m == expected);
- assert(m.keys().get_allocator() == A1(5));
- assert(m.values().get_allocator() == A2(5));
- // explicit(false)
- M m2 = {std::sorted_unique, il2, A1(5)};
- assert(m2 == m);
- assert(m2.keys().get_allocator() == A1(5));
- assert(m2.values().get_allocator() == A2(5));
- }
- {
- // flat_map(sorted_unique_t, initializer_list<value_type>, const key_compare&, const Allocator&);
- using C = test_less<int>;
- using A1 = test_allocator<int>;
- using A2 = test_allocator<short>;
- using M = std::flat_map<int, short, C, std::vector<int, A1>, std::deque<short, A2>>;
- auto m = M(std::sorted_unique, il2, C(3), A1(5));
- assert((m == M{{1, 1}, {2, 2}, {4, 4}, {5, 5}}));
- assert(m.key_comp() == C(3));
- assert(m.keys().get_allocator() == A1(5));
- assert(m.values().get_allocator() == A2(5));
- }
- {
- // flat_map(sorted_unique_t, initializer_list<value_type>, const key_compare&, const Allocator&);
- // explicit(false)
- using A1 = test_allocator<short>;
- using A2 = test_allocator<int>;
- using M = std::flat_map<short, int, std::less<int>, std::deque<short, A1>, std::vector<int, A2>>;
- M m = {std::sorted_unique, il3, {}, A1(5)}; // implicit ctor
- assert((m == M{{1, 1}, {2, 2}, {4, 4}, {5, 5}}));
- assert(m.keys().get_allocator() == A1(5));
- assert(m.values().get_allocator() == A2(5));
- }
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_iter_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_iter_iter.pass.cpp
index 8eb7547e917cc..710d45ed36f72 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_iter_iter.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_iter_iter.pass.cpp
@@ -20,45 +20,26 @@
#include <deque>
#include <flat_map>
#include <functional>
+#include <type_traits>
#include <vector>
+#include "MinSequenceContainer.h"
#include "min_allocator.h"
#include "test_allocator.h"
#include "test_iterators.h"
#include "test_macros.h"
#include "../../../test_compare.h"
-int main(int, char**) {
- {
- // 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_map<int, int, C, V1, V1>;
- using M2 = std::flat_map<int, int, C, V1, V2>;
- using M3 = std::flat_map<int, int, C, V2, V1>;
- using Iter1 = typename M1::iterator;
- using Iter2 = typename M2::iterator;
- using Iter3 = typename M3::iterator;
- static_assert(std::is_constructible_v<M1, std::sorted_unique_t, Iter1, Iter1, const A1&>);
- static_assert(!std::is_constructible_v<M1, std::sorted_unique_t, Iter1, Iter1, const A2&>);
- static_assert(!std::is_constructible_v<M2, std::sorted_unique_t, Iter2, Iter2, const A2&>);
- static_assert(!std::is_constructible_v<M3, std::sorted_unique_t, Iter3, Iter3, const A2&>);
+template <class KeyContainer, class ValueContainer>
+constexpr void test() {
+ using Key = typename KeyContainer::value_type;
+ using Value = typename ValueContainer::value_type;
- static_assert(std::is_constructible_v<M1, std::sorted_unique_t, Iter1, Iter1, const C&, const A1&>);
- static_assert(!std::is_constructible_v<M1, std::sorted_unique_t, Iter1, Iter1, const C&, const A2&>);
- static_assert(!std::is_constructible_v<M2, std::sorted_unique_t, Iter2, Iter2, const C&, const A2&>);
- static_assert(!std::is_constructible_v<M3, std::sorted_unique_t, Iter3, Iter3, const C&, const A2&>);
- }
{
// flat_map(sorted_unique_t, InputIterator, InputIterator);
// cpp17_input_iterator
- using M = std::flat_map<int, int>;
- using P = std::pair<int, int>;
+ using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
+ using P = std::pair<Key, Value>;
P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
auto m = M(std::sorted_unique, cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 4));
auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
@@ -71,18 +52,19 @@ int main(int, char**) {
{
// flat_map(sorted_unique_t, InputIterator, InputIterator);
// contiguous iterator
- using C = test_less<int>;
- using M = std::flat_map<int, int, C, std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>;
- std::pair<int, int> ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
- auto m = M(std::sorted_unique, ar, ar + 4);
- auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
+ using C = test_less<Key>;
+ using P = std::pair<Key, Value>;
+ using M = std::flat_map<Key, Value, C, KeyContainer, ValueContainer>;
+ P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
+ auto m = M(std::sorted_unique, ar, ar + 4);
+ auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
assert(m == expected);
}
- {
+ if (!std::is_constant_evaluated()) {
// flat_map(sorted_unique_t, InputIterator, InputIterator, const key_compare&);
// cpp_17_input_iterator
- using M = std::flat_map<int, int, std::function<bool(int, int)>>;
- using P = std::pair<int, int>;
+ using M = std::flat_map<Key, Value, std::function<bool(Key, Value)>>;
+ using P = std::pair<Key, Value>;
P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
auto m = M(std::sorted_unique,
cpp17_input_iterator<const P*>(ar),
@@ -101,8 +83,8 @@ int main(int, char**) {
{
// flat_map(sorted_unique_t, InputIterator, InputIterator, const key_compare&);
// greater
- using M = std::flat_map<int, int, std::greater<int>, std::deque<int, min_allocator<int>>, std::vector<int>>;
- using P = std::pair<int, int>;
+ using M = std::flat_map<Key, Value, std::greater<int>, KeyContainer, ValueContainer>;
+ using P = std::pair<Key, Value>;
P ar[] = {{5, 5}, {4, 4}, {2, 2}, {1, 1}};
auto m = M(std::sorted_unique,
cpp17_input_iterator<const P*>(ar),
@@ -113,18 +95,22 @@ int main(int, char**) {
{
// flat_map(sorted_unique_t, InputIterator, InputIterator, const key_compare&);
// contiguous iterator
- using C = test_less<int>;
- using M = std::flat_map<int, int, C, std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>;
- std::pair<int, int> ar[1] = {{42, 42}};
- auto m = M(std::sorted_unique, ar, ar, C(5));
+ using C = test_less<Key>;
+ using M = std::flat_map<Key, Value, C, KeyContainer, ValueContainer>;
+ std::pair<Key, Value> ar[1] = {{42, 42}};
+ auto m = M(std::sorted_unique, ar, ar, C(5));
assert(m.empty());
assert(m.key_comp() == C(5));
}
+}
+
+template <template <class...> class KeyContainer, template <class...> class ValueContainer>
+constexpr void test_alloc() {
{
// flat_map(sorted_unique_t, InputIterator , InputIterator, const Allocator&)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
- using M = std::flat_map<int, short, std::less<int>, std::vector<int, A1>, std::deque<short, A2>>;
+ using M = std::flat_map<int, short, std::less<int>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
using P = std::pair<int, int>;
P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
auto m = M(std::sorted_unique, ar, ar + 4, A1(5));
@@ -144,7 +130,7 @@ int main(int, char**) {
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
- using M = std::flat_map<int, short, C, std::vector<int, A1>, std::deque<short, A2>>;
+ using M = std::flat_map<int, short, C, KeyContainer<int, A1>, ValueContainer<short, A2>>;
using P = std::pair<int, int>;
P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
auto m = M(std::sorted_unique, ar, ar + 4, C(3), A1(5));
@@ -158,7 +144,7 @@ int main(int, char**) {
// explicit(false)
using A1 = test_allocator<short>;
using A2 = test_allocator<int>;
- using M = std::flat_map<short, int, std::less<int>, std::deque<short, A1>, std::vector<int, A2>>;
+ using M = std::flat_map<short, int, std::less<int>, KeyContainer<short, A1>, ValueContainer<int, A2>>;
using P = std::pair<int, int>;
P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
M m = {std::sorted_unique, ar, ar + 4, {}, A1(5)}; // implicit ctor
@@ -166,6 +152,59 @@ int main(int, char**) {
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
+}
+
+constexpr bool 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_map<int, int, C, V1, V1>;
+ using M2 = std::flat_map<int, int, C, V1, V2>;
+ using M3 = std::flat_map<int, int, C, V2, V1>;
+ using Iter1 = typename M1::iterator;
+ using Iter2 = typename M2::iterator;
+ using Iter3 = typename M3::iterator;
+ static_assert(std::is_constructible_v<M1, std::sorted_unique_t, Iter1, Iter1, const A1&>);
+ static_assert(!std::is_constructible_v<M1, std::sorted_unique_t, Iter1, Iter1, const A2&>);
+ static_assert(!std::is_constructible_v<M2, std::sorted_unique_t, Iter2, Iter2, const A2&>);
+ static_assert(!std::is_constructible_v<M3, std::sorted_unique_t, Iter3, Iter3, const A2&>);
+
+ static_assert(std::is_constructible_v<M1, std::sorted_unique_t, Iter1, Iter1, const C&, const A1&>);
+ static_assert(!std::is_constructible_v<M1, std::sorted_unique_t, Iter1, Iter1, const C&, const A2&>);
+ static_assert(!std::is_constructible_v<M2, std::sorted_unique_t, Iter2, Iter2, const C&, const A2&>);
+ static_assert(!std::is_constructible_v<M3, std::sorted_unique_t, Iter3, Iter3, const C&, const A2&>);
+ }
+
+ test<std::vector<int>, std::vector<int>>();
+ test<std::vector<int>, std::vector<double>>();
+ test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
+ test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
+ test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
+
+ test_alloc<std::vector, std::vector>();
+
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ test_alloc<std::deque, std::deque>();
+ }
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.erasure/erase_if.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.erasure/erase_if.pass.cpp
index fb0563eec5376..07ed235ce7edc 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.erasure/erase_if.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.erasure/erase_if.pass.cpp
@@ -32,7 +32,7 @@ static_assert(HasStdErase<std::vector<int>>);
static_assert(!HasStdErase<std::flat_map<int, int>>);
template <class M>
-M make(std::initializer_list<int> vals) {
+constexpr M make(std::initializer_list<int> vals) {
M ret;
for (int v : vals)
ret[static_cast<typename M::key_type>(v)] = static_cast<typename M::mapped_type>(v + 10);
@@ -40,8 +40,8 @@ M make(std::initializer_list<int> vals) {
}
template <class M, class Pred>
-void test0(
- std::initializer_list<int> vals, Pred p, std::initializer_list<int> expected, std::size_t expected_erased_count) {
+constexpr void
+test0(std::initializer_list<int> vals, Pred p, std::initializer_list<int> expected, std::size_t expected_erased_count) {
M s = make<M>(vals);
ASSERT_SAME_TYPE(typename M::size_type, decltype(std::erase_if(s, p)));
assert(expected_erased_count == std::erase_if(s, p));
@@ -49,7 +49,7 @@ void test0(
}
template <class S>
-void test() {
+constexpr void test() {
// Test all the plausible signatures for this predicate.
auto is1 = [](typename S::const_reference v) { return v.first == 1; };
auto is2 = [](typename S::value_type v) { return v.first == 2; };
@@ -76,7 +76,7 @@ void test() {
test0<S>({1, 2, 3}, False, {1, 2, 3}, 0);
}
-int main(int, char**) {
+constexpr bool test() {
test<std::flat_map<int, char>>();
test<std::flat_map<int,
char,
@@ -84,10 +84,24 @@ int main(int, char**) {
std::vector<int, min_allocator<int>>,
std::vector<char, min_allocator<char>>>>();
test<std::flat_map<int, char, std::greater<int>, std::vector<int, test_allocator<int>>>>();
- test<std::flat_map<int, char, std::less<int>, std::deque<int, min_allocator<int>>>>();
- test<std::flat_map<int, char, std::greater<int>, std::deque<int, test_allocator<int>>>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::flat_map<int, char, std::less<int>, std::deque<int, min_allocator<int>>>>();
+ test<std::flat_map<int, char, std::greater<int>, std::deque<int, test_allocator<int>>>>();
+ }
test<std::flat_map<long, int>>();
test<std::flat_map<double, int>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/iterator.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/iterator.pass.cpp
index b63ce6b19ee16..1585c0c4a3215 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/iterator.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/iterator.pass.cpp
@@ -30,7 +30,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -70,9 +70,14 @@ void test() {
assert(i == m.begin());
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
- test<std::deque<int>, std::vector<char>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<char>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
@@ -92,5 +97,14 @@ int main(int, char**) {
assert(!(cii != ii1));
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/iterator_comparison.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/iterator_comparison.pass.cpp
index 1975d0ed86cc8..8cca1d4b3d5ec 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/iterator_comparison.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/iterator_comparison.pass.cpp
@@ -24,7 +24,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -145,11 +145,25 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
- test<std::deque<int>, std::vector<char>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<char>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/reverse_iterator.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/reverse_iterator.pass.cpp
index b4d76aac119a3..0c6c6d6c595f1 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/reverse_iterator.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/reverse_iterator.pass.cpp
@@ -25,48 +25,64 @@
#include <iterator>
+#include "MinSequenceContainer.h"
#include "test_macros.h"
+#include "min_allocator.h"
-int main(int, char**) {
+template <class KeyContainer, class ValueContainer>
+constexpr void test() {
+ using Key = typename KeyContainer::value_type;
+ using Value = typename ValueContainer::value_type;
+ using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
+ M m = {{1, 'a'}, {2, 'b'}, {3, 'c'}, {4, 'd'}};
+ const M& cm = m;
+ ASSERT_SAME_TYPE(decltype(m.rbegin()), typename M::reverse_iterator);
+ ASSERT_SAME_TYPE(decltype(m.crbegin()), typename M::const_reverse_iterator);
+ ASSERT_SAME_TYPE(decltype(cm.rbegin()), typename M::const_reverse_iterator);
+ ASSERT_SAME_TYPE(decltype(m.rend()), typename M::reverse_iterator);
+ ASSERT_SAME_TYPE(decltype(m.crend()), typename M::const_reverse_iterator);
+ ASSERT_SAME_TYPE(decltype(cm.rend()), typename M::const_reverse_iterator);
+ static_assert(noexcept(m.rbegin()));
+ static_assert(noexcept(cm.rbegin()));
+ static_assert(noexcept(m.crbegin()));
+ static_assert(noexcept(m.rend()));
+ static_assert(noexcept(cm.rend()));
+ static_assert(noexcept(m.crend()));
+ assert(m.size() == 4);
+ assert(std::distance(m.rbegin(), m.rend()) == 4);
+ assert(std::distance(cm.rbegin(), cm.rend()) == 4);
+ assert(std::distance(m.crbegin(), m.crend()) == 4);
+ assert(std::distance(cm.crbegin(), cm.crend()) == 4);
+ typename M::reverse_iterator i; // default-construct
+ ASSERT_SAME_TYPE(decltype(i->first), const int&);
+ ASSERT_SAME_TYPE(decltype(i->second), char&);
+ i = m.rbegin(); // move-assignment
+ typename M::const_reverse_iterator k = i; // converting constructor
+ assert(i == k); // comparison
+ for (int j = 4; j >= 1; --j, ++i) { // pre-increment
+ assert(i->first == j); // operator->
+ assert(i->second == 'a' + j - 1);
+ }
+ assert(i == m.rend());
+ for (int j = 1; j <= 4; ++j) {
+ --i; // pre-decrement
+ assert((*i).first == j);
+ assert((*i).second == 'a' + j - 1);
+ }
+ assert(i == m.rbegin());
+}
+
+constexpr bool test() {
+ test<std::vector<int>, std::vector<char>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
{
- using M = std::flat_map<int, char, std::less<int>, std::deque<int>, std::deque<char>>;
- M m = {{1, 'a'}, {2, 'b'}, {3, 'c'}, {4, 'd'}};
- const M& cm = m;
- ASSERT_SAME_TYPE(decltype(m.rbegin()), M::reverse_iterator);
- ASSERT_SAME_TYPE(decltype(m.crbegin()), M::const_reverse_iterator);
- ASSERT_SAME_TYPE(decltype(cm.rbegin()), M::const_reverse_iterator);
- ASSERT_SAME_TYPE(decltype(m.rend()), M::reverse_iterator);
- ASSERT_SAME_TYPE(decltype(m.crend()), M::const_reverse_iterator);
- ASSERT_SAME_TYPE(decltype(cm.rend()), M::const_reverse_iterator);
- static_assert(noexcept(m.rbegin()));
- static_assert(noexcept(cm.rbegin()));
- static_assert(noexcept(m.crbegin()));
- static_assert(noexcept(m.rend()));
- static_assert(noexcept(cm.rend()));
- static_assert(noexcept(m.crend()));
- assert(m.size() == 4);
- assert(std::distance(m.rbegin(), m.rend()) == 4);
- assert(std::distance(cm.rbegin(), cm.rend()) == 4);
- assert(std::distance(m.crbegin(), m.crend()) == 4);
- assert(std::distance(cm.crbegin(), cm.crend()) == 4);
- M::reverse_iterator i; // default-construct
- ASSERT_SAME_TYPE(decltype(i->first), const int&);
- ASSERT_SAME_TYPE(decltype(i->second), char&);
- i = m.rbegin(); // move-assignment
- M::const_reverse_iterator k = i; // converting constructor
- assert(i == k); // comparison
- for (int j = 4; j >= 1; --j, ++i) { // pre-increment
- assert(i->first == j); // operator->
- assert(i->second == 'a' + j - 1);
- }
- assert(i == m.rend());
- for (int j = 1; j <= 4; ++j) {
- --i; // pre-decrement
- assert((*i).first == j);
- assert((*i).second == 'a' + j - 1);
- }
- assert(i == m.rbegin());
+ test<std::deque<int>, std::vector<char>>();
}
+ test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
+ test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
+
{
// N3644 testing
using C = std::flat_map<int, char>;
@@ -82,6 +98,14 @@ int main(int, char**) {
assert(!(ii1 != cii));
assert(!(cii != ii1));
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/clear.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/clear.pass.cpp
index 30271eb55660b..0ba5bba99f7bc 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/clear.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/clear.pass.cpp
@@ -39,7 +39,7 @@ static_assert(
#endif
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -52,13 +52,27 @@ void test() {
assert(m.size() == 0);
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<int>>();
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/emplace.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/emplace.pass.cpp
index a54fcad639280..784ea49eac11d 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/emplace.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/emplace.pass.cpp
@@ -18,6 +18,7 @@
#include <deque>
#include <tuple>
#include <functional>
+#include <type_traits>
#include <vector>
#include "MinSequenceContainer.h"
@@ -39,7 +40,7 @@ static_assert(!CanEmplace<Map, Emplaceable>);
static_assert(!CanEmplace<Map, int, double>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -117,7 +118,7 @@ void test() {
}
template <class KeyContainer, class ValueContainer>
-void test_emplaceable() {
+constexpr void test_emplaceable() {
using M = std::flat_map<int, Emplaceable, std::less<int>, KeyContainer, ValueContainer>;
using R = std::pair<typename M::iterator, bool>;
@@ -143,23 +144,38 @@ void test_emplaceable() {
assert(m.begin()->second == Emplaceable(2, 3.5));
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
test_emplaceable<std::vector<int>, std::vector<Emplaceable>>();
- test_emplaceable<std::deque<int>, std::vector<Emplaceable>>();
test_emplaceable<MinSequenceContainer<int>, MinSequenceContainer<Emplaceable>>();
test_emplaceable<std::vector<int, min_allocator<int>>, std::vector<Emplaceable, min_allocator<Emplaceable>>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
{
+ test<std::deque<int>, std::vector<double>>();
+ test_emplaceable<std::deque<int>, std::vector<Emplaceable>>();
+ }
+
+ if (!std::is_constant_evaluated()) {
auto emplace_func = [](auto& m, auto key_arg, auto value_arg) {
m.emplace(std::piecewise_construct, std::tuple(key_arg), std::tuple(value_arg));
};
test_emplace_exception_guarantee(emplace_func);
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/emplace_hint.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/emplace_hint.pass.cpp
index 77c022a6de92b..ebcf36be1735c 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/emplace_hint.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/emplace_hint.pass.cpp
@@ -17,6 +17,7 @@
#include <cassert>
#include <deque>
#include <functional>
+#include <type_traits>
#include <vector>
#include "MinSequenceContainer.h"
@@ -42,7 +43,7 @@ static_assert(!CanEmplaceHint<Map, int, double>);
#endif
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -139,7 +140,7 @@ void test() {
}
template <class KeyContainer, class ValueContainer>
-void test_emplaceable() {
+constexpr void test_emplaceable() {
using M = std::flat_map<int, Emplaceable, std::less<int>, KeyContainer, ValueContainer>;
using R = M::iterator;
@@ -162,23 +163,37 @@ void test_emplaceable() {
assert(m.begin()->second == Emplaceable(2, 3.5));
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ test_emplaceable<std::deque<int>, std::vector<Emplaceable>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
test_emplaceable<std::vector<int>, std::vector<Emplaceable>>();
- test_emplaceable<std::deque<int>, std::vector<Emplaceable>>();
test_emplaceable<MinSequenceContainer<int>, MinSequenceContainer<Emplaceable>>();
test_emplaceable<std::vector<int, min_allocator<int>>, std::vector<Emplaceable, min_allocator<Emplaceable>>>();
- {
+ if (!std::is_constant_evaluated()) {
auto emplace_func = [](auto& m, auto key_arg, auto value_arg) {
m.emplace_hint(m.begin(), std::piecewise_construct, std::tuple(key_arg), std::tuple(value_arg));
};
test_emplace_exception_guarantee(emplace_func);
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_iter.pass.cpp
index 914e8b676a656..e368ae9663e9d 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_iter.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_iter.pass.cpp
@@ -18,6 +18,7 @@
#include <deque>
#include <flat_map>
#include <functional>
+#include <type_traits>
#include <utility>
#include <vector>
@@ -27,7 +28,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -136,16 +137,30 @@ void test() {
assert(i8 == m.end());
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
- {
+ if (!std::is_constant_evaluated()) {
auto erase_function = [](auto& m, auto) { m.erase(m.begin() + 2); };
test_erase_exception_guarantee(erase_function);
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_iter_iter.pass.cpp
index 0bc9208294029..7abf1e1db2e57 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_iter_iter.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_iter_iter.pass.cpp
@@ -17,6 +17,7 @@
#include <deque>
#include <flat_map>
#include <functional>
+#include <type_traits>
#include <utility>
#include <vector>
@@ -26,7 +27,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -95,15 +96,30 @@ void test() {
assert(i4 == m.end());
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
- {
+ if (!std::is_constant_evaluated()) {
auto erase_function = [](auto& m, auto) { m.erase(m.begin(), m.begin() + 2); };
test_erase_exception_guarantee(erase_function);
}
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_key.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_key.pass.cpp
index ef57b1cb5512d..8a004a77827b9 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_key.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_key.pass.cpp
@@ -26,7 +26,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer, class Compare = std::less<>>
-void test() {
+constexpr void test() {
using M = std::flat_map<int, char, Compare, KeyContainer, ValueContainer>;
auto make = [](std::initializer_list<int> il) {
@@ -70,14 +70,20 @@ void test() {
assert(m.empty());
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
test<std::vector<int>, std::vector<char>, std::greater<>>();
- test<std::deque<int>, std::vector<char>>();
+
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<char>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
- {
+ if (!std::is_constant_evaluated()) {
auto erase_function = [](auto& m, auto key_arg) {
using Map = std::decay_t<decltype(m)>;
using Key = typename Map::key_type;
@@ -87,5 +93,14 @@ int main(int, char**) {
test_erase_exception_guarantee(erase_function);
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_key_transparent.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_key_transparent.pass.cpp
index 3ba30757bf2c7..5320b1eed8137 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_key_transparent.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_key_transparent.pass.cpp
@@ -38,9 +38,9 @@ static_assert(!CanErase<const NonTransparentMap>);
template <class Key, class It>
struct HeterogeneousKey {
- explicit HeterogeneousKey(Key key, It it) : key_(key), it_(it) {}
- operator It() && { return it_; }
- auto operator<=>(Key key) const { return key_ <=> key; }
+ constexpr explicit HeterogeneousKey(Key key, It it) : key_(key), it_(it) {}
+ constexpr operator It() && { return it_; }
+ constexpr auto operator<=>(Key key) const { return key_ <=> key; }
friend bool operator<(const HeterogeneousKey&, const HeterogeneousKey&) {
assert(false);
return false;
@@ -50,7 +50,7 @@ struct HeterogeneousKey {
};
template <class KeyContainer, class ValueContainer>
-void test_simple() {
+constexpr void test_simple() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -71,7 +71,7 @@ void test_simple() {
}
template <class KeyContainer, class ValueContainer>
-void test_transparent_comparator() {
+constexpr void test_transparent_comparator() {
using M = std::flat_map<std::string, int, TransparentComparator, KeyContainer, ValueContainer>;
M m = {{"alpha", 1}, {"beta", 2}, {"epsilon", 3}, {"eta", 4}, {"gamma", 5}};
ASSERT_SAME_TYPE(decltype(m.erase(Transparent<std::string>{"abc"})), typename M::size_type);
@@ -87,18 +87,24 @@ void test_transparent_comparator() {
assert(m == expected);
}
-int main(int, char**) {
+constexpr bool test() {
test_simple<std::vector<int>, std::vector<double>>();
- test_simple<std::deque<int>, std::vector<double>>();
test_simple<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test_simple<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
test_transparent_comparator<std::vector<std::string>, std::vector<int>>();
- test_transparent_comparator<std::deque<std::string>, std::vector<int>>();
test_transparent_comparator<MinSequenceContainer<std::string>, MinSequenceContainer<int>>();
test_transparent_comparator<std::vector<std::string, min_allocator<std::string>>,
std::vector<int, min_allocator<int>>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test_simple<std::deque<int>, std::vector<double>>();
+ test_transparent_comparator<std::deque<std::string>, std::vector<int>>();
+ }
+
{
// P2077's HeterogeneousKey example
using M = std::flat_map<int, int, std::less<>>;
@@ -131,7 +137,7 @@ int main(int, char**) {
assert(n == 1);
assert(transparent_used);
}
- {
+ if (!std::is_constant_evaluated()) {
auto erase_transparent = [](auto& m, auto key_arg) {
using Map = std::decay_t<decltype(m)>;
using Key = typename Map::key_type;
@@ -140,5 +146,14 @@ int main(int, char**) {
test_erase_exception_guarantee(erase_transparent);
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/extract.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/extract.pass.cpp
index d8e4ce94efb9e..30219df3d60ba 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/extract.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/extract.pass.cpp
@@ -33,7 +33,7 @@ static_assert(!CanExtract<std::flat_map<int, int> const&>);
static_assert(!CanExtract<std::flat_map<int, int> const&&>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using M = std::flat_map<int, int, std::less<int>, KeyContainer, ValueContainer>;
M m = M({1, 2, 3}, {4, 5, 6});
@@ -49,9 +49,14 @@ void test() {
LIBCPP_ASSERT(m.values().size() == 0);
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<int>>();
- test<std::deque<int>, std::vector<int>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<int>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<int>>();
test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
{
@@ -67,7 +72,7 @@ int main(int, char**) {
LIBCPP_ASSERT(m.values().size() == 0);
}
- {
+ if (!std::is_constant_evaluated()) {
#ifndef TEST_HAS_NO_EXCEPTIONS
using KeyContainer = std::vector<int>;
using ValueContainer = ThrowOnMoveContainer<int>;
@@ -87,5 +92,15 @@ int main(int, char**) {
}
#endif
}
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_cv.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_cv.pass.cpp
index 7e667c4e4877b..93e263ed33d2f 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_cv.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_cv.pass.cpp
@@ -23,7 +23,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -64,13 +64,18 @@ void test() {
assert(r.first->second == 3.5);
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
- {
+ if (!std::is_constant_evaluated()) {
auto insert_func = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
using value_type = typename FlatMap::value_type;
@@ -79,5 +84,15 @@ int main(int, char**) {
};
test_emplace_exception_guarantee(insert_func);
}
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_initializer_list.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_initializer_list.pass.cpp
index 32be3ab8a95b3..1a49e30584df0 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_initializer_list.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_initializer_list.pass.cpp
@@ -12,10 +12,12 @@
// void insert(initializer_list<value_type> il);
+#include <algorithm>
#include <flat_map>
#include <cassert>
#include <functional>
#include <deque>
+#include <type_traits>
#include "MinSequenceContainer.h"
#include "../helpers.h"
@@ -23,7 +25,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -42,20 +44,29 @@ void test() {
{2, 2},
});
assert(m.size() == 4);
- assert(std::distance(m.begin(), m.end()) == 4);
- assert(*m.begin() == V(1, 1));
- assert(*std::next(m.begin()) == V(2, 1));
- assert(*std::next(m.begin(), 2) == V(3, 1));
- assert(*std::next(m.begin(), 3) == V(4, 1));
+ assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3, 4}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<Value>>{
+ {1, 1.5, 2},
+ {1, 1.5, 2},
+ {1, 1.5, 2},
+ {1, 1.5, 2},
+ });
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
- {
+ if (!std::is_constant_evaluated()) {
auto insert_func = [](auto& m, const auto& newValues) {
using FlatMap = std::decay_t<decltype(m)>;
using value_type = typename FlatMap::value_type;
@@ -64,5 +75,15 @@ int main(int, char**) {
};
test_insert_range_exception_guarantee(insert_func);
}
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_iter_cv.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_iter_cv.pass.cpp
index 4bbe0628317dc..f0fd5622ddefe 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_iter_cv.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_iter_cv.pass.cpp
@@ -23,7 +23,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -60,13 +60,18 @@ void test() {
assert(r->second == 3.5);
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
- {
+ if (!std::is_constant_evaluated()) {
auto insert_func = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
using value_type = typename FlatMap::value_type;
@@ -75,5 +80,15 @@ int main(int, char**) {
};
test_emplace_exception_guarantee(insert_func);
}
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_iter_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_iter_iter.pass.cpp
index 8455b19475fe4..2b6e5fafc555e 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_iter_iter.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_iter_iter.pass.cpp
@@ -37,7 +37,7 @@ static_assert(!CanInsert<Map, int, int>);
static_assert(!CanInsert<Map, cpp20_input_iterator<Pair*>, cpp20_input_iterator<Pair*>>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using P = std::pair<int, double>;
using M = std::flat_map<int, double, std::less<int>, KeyContainer, ValueContainer>;
@@ -67,23 +67,57 @@ void test() {
M m;
m.insert(cpp17_input_iterator<P*>(ar1), cpp17_input_iterator<P*>(ar1 + sizeof(ar1) / sizeof(ar1[0])));
assert(m.size() == 3);
- M expected{{1, 1}, {2, 1}, {3, 1}};
- assert(m == expected);
+
+ assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<double>>{
+ {1, 1.5, 2},
+ {1, 1.5, 2},
+ {1, 1.5, 2},
+ });
+
+ auto m_copy = m;
m.insert(cpp17_input_iterator<P*>(ar2), cpp17_input_iterator<P*>(ar2 + sizeof(ar2) / sizeof(ar2[0])));
assert(m.size() == 5);
- M expected2{{0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}};
- assert(m == expected2);
+
+ assert(std::ranges::equal(m.keys(), KeyContainer{0, 1, 2, 3, 4}));
+ check_possible_values(
+ m.values(),
+ std::vector<std::vector<double>>{
+ {1, 1.5, 2},
+ {m_copy[1]},
+ {m_copy[2]},
+ {m_copy[3]},
+ {1, 1.5, 2},
+ });
}
-int main(int, char**) {
+
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
- {
+ if (!std::is_constant_evaluated()) {
auto insert_func = [](auto& m, const auto& newValues) { m.insert(newValues.begin(), newValues.end()); };
test_insert_range_exception_guarantee(insert_func);
}
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_iter_rv.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_iter_rv.pass.cpp
index 034941b55eb80..afd0345fd5988 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_iter_rv.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_iter_rv.pass.cpp
@@ -22,7 +22,7 @@
#include "test_macros.h"
template <class Container, class Pair>
-void do_insert_iter_rv_test() {
+constexpr void do_insert_iter_rv_test() {
using M = Container;
using P = Pair;
using R = typename M::iterator;
@@ -53,7 +53,7 @@ void do_insert_iter_rv_test() {
}
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -64,17 +64,22 @@ void test() {
do_insert_iter_rv_test<M, CP>();
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::vector<int>, std::vector<MoveOnly>>();
- test<std::deque<int>, std::deque<double>>();
- test<std::deque<int>, std::deque<MoveOnly>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::deque<double>>();
+ test<std::deque<int>, std::deque<MoveOnly>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<MinSequenceContainer<int>, MinSequenceContainer<MoveOnly>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
test<std::vector<int, min_allocator<int>>, std::vector<MoveOnly, min_allocator<MoveOnly>>>();
- {
+ if (!std::is_constant_evaluated()) {
auto insert_func = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
using value_type = typename FlatMap::value_type;
@@ -84,5 +89,14 @@ int main(int, char**) {
test_emplace_exception_guarantee(insert_func);
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_or_assign.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_or_assign.pass.cpp
index 398a7a1a4052e..a93c86d85d07d 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_or_assign.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_or_assign.pass.cpp
@@ -78,7 +78,7 @@ static_assert(!CanInsertOrAssignIter<std::flat_map<int, ConstructFrom<V>>, int&&
static_assert(!CanInsertOrAssignIter<std::flat_map<int, AssignFrom<V>>, int&&, V>);
template <class KeyContainer, class ValueContainer>
-void test_cv_key() {
+constexpr void test_cv_key() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -194,7 +194,7 @@ void test_cv_key() {
}
template <class KeyContainer, class ValueContainer>
-void test_rv_key() {
+constexpr void test_rv_key() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -311,16 +311,30 @@ void test_rv_key() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test_cv_key<std::vector<int>, std::vector<Moveable>>();
- test_cv_key<std::deque<int>, std::vector<Moveable>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test_cv_key<std::deque<int>, std::vector<Moveable>>();
+ test_rv_key<std::deque<Moveable>, std::vector<Moveable>>();
+ }
test_cv_key<MinSequenceContainer<int>, MinSequenceContainer<Moveable>>();
test_cv_key<std::vector<int, min_allocator<int>>, std::vector<Moveable, min_allocator<Moveable>>>();
test_rv_key<std::vector<Moveable>, std::vector<Moveable>>();
- test_rv_key<std::deque<Moveable>, std::vector<Moveable>>();
test_rv_key<MinSequenceContainer<Moveable>, MinSequenceContainer<Moveable>>();
test_rv_key<std::vector<Moveable, min_allocator<Moveable>>, std::vector<Moveable, min_allocator<Moveable>>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_or_assign_transparent.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_or_assign_transparent.pass.cpp
index 636c4edfe551d..23e913769cf30 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_or_assign_transparent.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_or_assign_transparent.pass.cpp
@@ -94,7 +94,7 @@ static_assert(
!CanInsertOrAssignIter<std::flat_map<int, AssignFrom<V>, TransparentComparator>, ConvertibleTransparent<int>, V>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -212,9 +212,14 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<Moveable>>();
- test<std::deque<int>, std::vector<Moveable>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<Moveable>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<Moveable>>();
test<std::vector<int, min_allocator<int>>, std::vector<Moveable, min_allocator<Moveable>>>();
@@ -237,23 +242,34 @@ int main(int, char**) {
assert(transparent_used);
}
- {
- auto insert_or_assign = [](auto& m, auto key_arg, auto value_arg) {
- using M = std::decay_t<decltype(m)>;
- using Key = typename M::key_type;
- m.insert_or_assign(ConvertibleTransparent<Key>{key_arg}, value_arg);
- };
- test_emplace_exception_guarantee(insert_or_assign);
- }
+ if (!std::is_constant_evaluated()) {
+ {
+ auto insert_or_assign = [](auto& m, auto key_arg, auto value_arg) {
+ using M = std::decay_t<decltype(m)>;
+ using Key = typename M::key_type;
+ m.insert_or_assign(ConvertibleTransparent<Key>{key_arg}, value_arg);
+ };
+ test_emplace_exception_guarantee(insert_or_assign);
+ }
- {
- auto insert_or_assign_iter = [](auto& m, auto key_arg, auto value_arg) {
- using M = std::decay_t<decltype(m)>;
- using Key = typename M::key_type;
- m.insert_or_assign(m.begin(), ConvertibleTransparent<Key>{key_arg}, value_arg);
- };
- test_emplace_exception_guarantee(insert_or_assign_iter);
+ {
+ auto insert_or_assign_iter = [](auto& m, auto key_arg, auto value_arg) {
+ using M = std::decay_t<decltype(m)>;
+ using Key = typename M::key_type;
+ m.insert_or_assign(m.begin(), ConvertibleTransparent<Key>{key_arg}, value_arg);
+ };
+ test_emplace_exception_guarantee(insert_or_assign_iter);
+ }
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_range.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_range.pass.cpp
index a2e64431a3c25..7339f58eaffdc 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_range.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_range.pass.cpp
@@ -39,7 +39,7 @@ static_assert(!CanInsertRange<Map, std::ranges::subrange<int*>>);
static_assert(!CanInsertRange<Map, std::ranges::subrange<double*>>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
@@ -68,7 +68,7 @@ void test() {
{
// The "uniquing" part uses the comparator, not operator==.
struct ModTen {
- bool operator()(int a, int b) const { return (a % 10) < (b % 10); }
+ constexpr bool operator()(int a, int b) const { return (a % 10) < (b % 10); }
};
using P = std::pair<int, int>;
using M = std::flat_map<Key, Value, ModTen, KeyContainer, ValueContainer>;
@@ -79,9 +79,14 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<int>>();
- test<std::deque<int>, std::vector<int>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<int>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<int>>();
test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
{
@@ -95,15 +100,25 @@ int main(int, char**) {
{
// The element type of the range doesn't need to be std::pair (P2767).
std::pair<int, int> pa[] = {{3, 3}, {1, 1}, {4, 4}, {1, 1}, {5, 5}};
- std::deque<std::reference_wrapper<std::pair<int, int>>> a(pa, pa + 5);
+ std::vector<std::reference_wrapper<std::pair<int, int>>> a(pa, pa + 5);
std::flat_map<int, int> m;
m.insert_range(a);
std::pair<int, int> expected[] = {{1, 1}, {3, 3}, {4, 4}, {5, 5}};
assert(std::ranges::equal(m, expected));
}
- {
+ if (!std::is_constant_evaluated()) {
auto insert_func = [](auto& m, const auto& newValues) { m.insert_range(newValues); };
test_insert_range_exception_guarantee(insert_func);
}
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_rv.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_rv.pass.cpp
index 9ea7a6a636666..60af8b654e57a 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_rv.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_rv.pass.cpp
@@ -25,7 +25,7 @@
#include "../helpers.h"
template <class Container, class Pair>
-void do_insert_rv_test() {
+constexpr void do_insert_rv_test() {
using M = Container;
using P = Pair;
using R = std::pair<typename M::iterator, bool>;
@@ -60,7 +60,7 @@ void do_insert_rv_test() {
}
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -72,9 +72,14 @@ void test() {
do_insert_rv_test<M, CP>();
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<MoveOnly>>();
- test<std::deque<int>, std::vector<MoveOnly>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<MoveOnly>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<MoveOnly>>();
test<std::vector<int, min_allocator<int>>, std::vector<MoveOnly, min_allocator<MoveOnly>>>();
@@ -110,7 +115,7 @@ int main(int, char**) {
assert(r.first->first == 3);
assert(r.first->second == 3);
}
- {
+ if (!std::is_constant_evaluated()) {
auto insert_func = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
using value_type = typename FlatMap::value_type;
@@ -120,5 +125,14 @@ int main(int, char**) {
test_emplace_exception_guarantee(insert_func);
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_sorted_initializer_list.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_sorted_initializer_list.pass.cpp
index 08d2caf349879..e0692ffe40fea 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_sorted_initializer_list.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_sorted_initializer_list.pass.cpp
@@ -23,7 +23,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -39,20 +39,34 @@ void test() {
});
assert(m.size() == 5);
assert(std::distance(m.begin(), m.end()) == 5);
+
assert(*m.begin() == V(0, 1));
- assert(*std::next(m.begin()) == V(1, 1));
- assert(*std::next(m.begin(), 2) == V(2, 1));
- assert(*std::next(m.begin(), 3) == V(3, 1));
- assert(*std::next(m.begin(), 4) == V(4, 1));
+ auto v1 = *std::next(m.begin());
+ assert(v1.first == 1);
+ assert(v1.second == 1 || v1.second == 1.5 || v1.second == 2);
+ auto v2 = *std::next(m.begin(), 2);
+ assert(v2.first == 2);
+ assert(v2.second == 1);
+ auto v3 = *std::next(m.begin(), 3);
+ assert(v3.first == 3);
+ assert(v3.second == 1 || v3.second == 1.5 || v3.second == 2);
+ auto v4 = *std::next(m.begin(), 4);
+ assert(v4.first == 4);
+ assert(v4.second == 1);
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
- {
+ if (!std::is_constant_evaluated()) {
auto insert_func = [](auto& m, const auto& newValues) {
using FlatMap = std::decay_t<decltype(m)>;
using value_type = typename FlatMap::value_type;
@@ -62,5 +76,14 @@ int main(int, char**) {
test_insert_range_exception_guarantee(insert_func);
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_sorted_iter_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_sorted_iter_iter.pass.cpp
index 18a3b571a4199..61ffb689af367 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_sorted_iter_iter.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_sorted_iter_iter.pass.cpp
@@ -37,7 +37,7 @@ static_assert(!CanInsert<Map, std::sorted_unique_t, int, int>);
static_assert(!CanInsert<Map, std::sorted_unique_t, cpp20_input_iterator<Pair*>, cpp20_input_iterator<Pair*>>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -69,18 +69,32 @@ void test() {
assert(m == expected2);
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
- {
+ if (!std::is_constant_evaluated()) {
auto insert_func = [](auto& m, const auto& newValues) {
m.insert(std::sorted_unique, newValues.begin(), newValues.end());
};
test_insert_range_exception_guarantee(insert_func);
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_transparent.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_transparent.pass.cpp
index 75cabb70630f3..ecc5c54075e60 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_transparent.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_transparent.pass.cpp
@@ -41,98 +41,42 @@ static_assert(CanInsert<Map, Iter, std::tuple<short, double>&&>);
static_assert(!CanInsert<Map, int>);
static_assert(!CanInsert<Map, Iter, int>);
-static int expensive_comparisons = 0;
-static int cheap_comparisons = 0;
-
-struct CompareCounter {
- int i_ = 0;
- CompareCounter(int i) : i_(i) {}
- friend auto operator<=>(const CompareCounter& x, const CompareCounter& y) {
- expensive_comparisons += 1;
- return x.i_ <=> y.i_;
- }
- bool operator==(const CompareCounter&) const = default;
- friend auto operator<=>(const CompareCounter& x, int y) {
- cheap_comparisons += 1;
- return x.i_ <=> y;
- }
-};
+constexpr bool test() {
+ {
+ // template<class K> pair<iterator, bool> insert(P&& x);
+ bool transparent_used = false;
+ TransparentComparator c(transparent_used);
+ using M = std::flat_map<int, int, TransparentComparator>;
+ M m(std::sorted_unique, {{1, 1}, {2, 2}, {4, 4}}, c);
+ assert(!transparent_used);
-template <class KeyContainer, class ValueContainer>
-void test() {
- using Key = typename KeyContainer::value_type;
- using Value = typename ValueContainer::value_type;
- using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
+ std::same_as<std::pair<typename M::iterator, bool>> decltype(auto) res =
+ m.insert(std::pair(ConvertibleTransparent<int>{3}, 3));
- const std::pair<int, int> expected[] = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}};
- {
- // insert(P&&)
+ assert(res.second);
+ assert(res.first->first == 3);
+ assert(res.first->second == 3);
// Unlike flat_set, here we can't use key_compare to compare value_type versus P,
// so we must eagerly convert to value_type.
- M m = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
- expensive_comparisons = 0;
- cheap_comparisons = 0;
- std::same_as<std::pair<typename M::iterator, bool>> auto p =
- m.insert(std::make_pair(3, 3)); // conversion happens first
- assert(expensive_comparisons >= 2);
- assert(cheap_comparisons == 0);
- assert(p == std::make_pair(m.begin() + 2, true));
- assert(std::ranges::equal(m, expected));
- }
- {
- // insert(const_iterator, P&&)
- M m = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
- expensive_comparisons = 0;
- cheap_comparisons = 0;
- std::same_as<typename M::iterator> auto it = m.insert(m.begin(), std::make_pair(3, 3));
- assert(expensive_comparisons >= 2);
- assert(cheap_comparisons == 0);
- assert(it == m.begin() + 2);
- assert(std::ranges::equal(m, expected));
- }
- {
- // insert(value_type&&)
- M m = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
- expensive_comparisons = 0;
- cheap_comparisons = 0;
- std::same_as<std::pair<typename M::iterator, bool>> auto p =
- m.insert(std::make_pair(3, 3)); // conversion happens last
- assert(expensive_comparisons >= 2);
- assert(cheap_comparisons == 0);
- assert(p == std::make_pair(m.begin() + 2, true));
- assert(std::ranges::equal(m, expected));
- }
- {
- // insert(const_iterator, value_type&&)
- M m = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
- expensive_comparisons = 0;
- cheap_comparisons = 0;
- std::same_as<typename M::iterator> auto it = m.insert(m.begin(), std::make_pair(3, 3));
- assert(expensive_comparisons >= 2);
- assert(cheap_comparisons == 0);
- assert(it == m.begin() + 2);
- assert(std::ranges::equal(m, expected));
+ assert(!transparent_used);
}
{
- // emplace(Args&&...)
- M m = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
- expensive_comparisons = 0;
- cheap_comparisons = 0;
- std::same_as<std::pair<typename M::iterator, bool>> auto p =
- m.emplace(std::make_pair(3, 3)); // conversion happens first
- assert(expensive_comparisons >= 2);
- assert(cheap_comparisons == 0);
- assert(p == std::make_pair(m.begin() + 2, true));
- assert(std::ranges::equal(m, expected));
- }
-}
+ // template<class K> iterator insert(const_iterator hint, P&& x);
+ bool transparent_used = false;
+ TransparentComparator c(transparent_used);
+ using M = std::flat_map<int, int, TransparentComparator>;
+ M m(std::sorted_unique, {{1, 1}, {2, 2}, {4, 4}}, c);
+ assert(!transparent_used);
-int main(int, char**) {
- test<std::vector<CompareCounter>, std::vector<double>>();
- test<std::deque<CompareCounter>, std::vector<double>>();
- test<MinSequenceContainer<CompareCounter>, MinSequenceContainer<double>>();
- test<std::vector<CompareCounter, min_allocator<CompareCounter>>, std::vector<double, min_allocator<double>>>();
+ std::same_as<typename M::iterator> decltype(auto) res =
+ m.insert(m.begin(), std::pair(ConvertibleTransparent<int>{3}, 3));
+ assert(res->first == 3);
+ assert(res->second == 3);
+ // Unlike flat_set, here we can't use key_compare to compare value_type versus P,
+ // so we must eagerly convert to value_type.
+ assert(!transparent_used);
+ }
{
// no ambiguity between insert(pos, P&&) and insert(first, last)
using M = std::flat_map<int, int>;
@@ -145,23 +89,36 @@ int main(int, char**) {
ASSERT_SAME_TYPE(decltype(m.insert(m.begin(), Evil())), M::iterator);
ASSERT_SAME_TYPE(decltype(m.insert(m.begin(), m.end())), void);
}
- {
- auto insert_func = [](auto& m, auto key_arg, auto value_arg) {
- using FlatMap = std::decay_t<decltype(m)>;
- using tuple_type = std::tuple<typename FlatMap::key_type, typename FlatMap::mapped_type>;
- tuple_type t(key_arg, value_arg);
- m.insert(t);
- };
- test_emplace_exception_guarantee(insert_func);
- }
- {
- auto insert_func_iter = [](auto& m, auto key_arg, auto value_arg) {
- using FlatMap = std::decay_t<decltype(m)>;
- using tuple_type = std::tuple<typename FlatMap::key_type, typename FlatMap::mapped_type>;
- tuple_type t(key_arg, value_arg);
- m.insert(m.begin(), t);
- };
- test_emplace_exception_guarantee(insert_func_iter);
+
+ if (!std::is_constant_evaluated()) {
+ {
+ auto insert_func = [](auto& m, auto key_arg, auto value_arg) {
+ using FlatMap = std::decay_t<decltype(m)>;
+ using tuple_type = std::tuple<typename FlatMap::key_type, typename FlatMap::mapped_type>;
+ tuple_type t(key_arg, value_arg);
+ m.insert(t);
+ };
+ test_emplace_exception_guarantee(insert_func);
+ }
+ {
+ auto insert_func_iter = [](auto& m, auto key_arg, auto value_arg) {
+ using FlatMap = std::decay_t<decltype(m)>;
+ using tuple_type = std::tuple<typename FlatMap::key_type, typename FlatMap::mapped_type>;
+ tuple_type t(key_arg, value_arg);
+ m.insert(m.begin(), t);
+ };
+ test_emplace_exception_guarantee(insert_func_iter);
+ }
}
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/replace.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/replace.pass.cpp
index 5ca811d761520..2c10725903e4d 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/replace.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/replace.pass.cpp
@@ -33,7 +33,7 @@ static_assert(!CanReplace<Map, std::vector<int>, const std::vector<int>&>);
static_assert(!CanReplace<Map, const std::vector<int>&, const std::vector<int>&>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -49,13 +49,18 @@ void test() {
assert(std::ranges::equal(m.values(), expected_values));
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
- {
+ if (!std::is_constant_evaluated()) {
#ifndef TEST_HAS_NO_EXCEPTIONS
using KeyContainer = std::vector<int>;
using ValueContainer = ThrowOnMoveContainer<int>;
@@ -76,5 +81,15 @@ int main(int, char**) {
}
#endif
}
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/swap_free.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/swap_free.pass.cpp
index 98c60c1488cf5..163e74c349479 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/swap_free.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/swap_free.pass.cpp
@@ -39,7 +39,7 @@ static_assert(
#endif
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -87,11 +87,25 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/swap_member.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/swap_member.pass.cpp
index d2d8f5673edeb..e65a3c1970f85 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/swap_member.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/swap_member.pass.cpp
@@ -38,7 +38,7 @@ static_assert(
#endif
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -85,11 +85,25 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
- test<std::deque<int>, std::vector<double>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<double>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/try_emplace.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/try_emplace.pass.cpp
index 4be2fe1c4333e..ee6e53d378026 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/try_emplace.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/try_emplace.pass.cpp
@@ -63,7 +63,7 @@ static_assert(!CanTryEmplace<Map, Iter, Emplaceable, const Emplaceable&>);
static_assert(!CanTryEmplace<Map, Iter, Emplaceable, int>);
template <class KeyContainer, class ValueContainer>
-void test_ck() {
+constexpr void test_ck() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -101,7 +101,7 @@ void test_ck() {
assert(r3.first->second.get() == 5); // value
Moveable mv3(-1, 3.0);
- std::same_as<R> decltype(auto) r4 = m.try_emplace(117, std::move(mv2));
+ std::same_as<R> decltype(auto) r4 = m.try_emplace(117, std::move(mv3));
assert(m.size() == 13);
assert(r4.second); // was inserted
assert(mv2.moved()); // was moved from
@@ -135,7 +135,7 @@ void test_ck() {
}
template <class KeyContainer, class ValueContainer>
-void test_rk() {
+constexpr void test_rk() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -193,54 +193,70 @@ void test_rk() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test_ck<std::vector<int>, std::vector<Moveable>>();
- test_ck<std::deque<int>, std::vector<Moveable>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test_ck<std::deque<int>, std::vector<Moveable>>();
+ test_rk<std::deque<Moveable>, std::vector<Moveable>>();
+ }
test_ck<MinSequenceContainer<int>, MinSequenceContainer<Moveable>>();
test_ck<std::vector<int, min_allocator<int>>, std::vector<Moveable, min_allocator<Moveable>>>();
test_rk<std::vector<Moveable>, std::vector<Moveable>>();
- test_rk<std::deque<Moveable>, std::vector<Moveable>>();
test_rk<MinSequenceContainer<Moveable>, MinSequenceContainer<Moveable>>();
test_rk<std::vector<Moveable, min_allocator<Moveable>>, std::vector<Moveable, min_allocator<Moveable>>>();
- {
- auto try_emplace_ck = [](auto& m, auto key_arg, auto value_arg) {
- using M = std::decay_t<decltype(m)>;
- using Key = typename M::key_type;
- const Key key{key_arg};
- m.try_emplace(key, value_arg);
- };
- test_emplace_exception_guarantee(try_emplace_ck);
- }
+ if (!std::is_constant_evaluated()) {
+ {
+ auto try_emplace_ck = [](auto& m, auto key_arg, auto value_arg) {
+ using M = std::decay_t<decltype(m)>;
+ using Key = typename M::key_type;
+ const Key key{key_arg};
+ m.try_emplace(key, value_arg);
+ };
+ test_emplace_exception_guarantee(try_emplace_ck);
+ }
- {
- auto try_emplace_rk = [](auto& m, auto key_arg, auto value_arg) {
- using M = std::decay_t<decltype(m)>;
- using Key = typename M::key_type;
- m.try_emplace(Key{key_arg}, value_arg);
- };
- test_emplace_exception_guarantee(try_emplace_rk);
- }
+ {
+ auto try_emplace_rk = [](auto& m, auto key_arg, auto value_arg) {
+ using M = std::decay_t<decltype(m)>;
+ using Key = typename M::key_type;
+ m.try_emplace(Key{key_arg}, value_arg);
+ };
+ test_emplace_exception_guarantee(try_emplace_rk);
+ }
- {
- auto try_emplace_iter_ck = [](auto& m, auto key_arg, auto value_arg) {
- using M = std::decay_t<decltype(m)>;
- using Key = typename M::key_type;
- const Key key{key_arg};
- m.try_emplace(m.begin(), key, value_arg);
- };
- test_emplace_exception_guarantee(try_emplace_iter_ck);
- }
+ {
+ auto try_emplace_iter_ck = [](auto& m, auto key_arg, auto value_arg) {
+ using M = std::decay_t<decltype(m)>;
+ using Key = typename M::key_type;
+ const Key key{key_arg};
+ m.try_emplace(m.begin(), key, value_arg);
+ };
+ test_emplace_exception_guarantee(try_emplace_iter_ck);
+ }
- {
- auto try_emplace_iter_rk = [](auto& m, auto key_arg, auto value_arg) {
- using M = std::decay_t<decltype(m)>;
- using Key = typename M::key_type;
- m.try_emplace(m.begin(), Key{key_arg}, value_arg);
- };
- test_emplace_exception_guarantee(try_emplace_iter_rk);
+ {
+ auto try_emplace_iter_rk = [](auto& m, auto key_arg, auto value_arg) {
+ using M = std::decay_t<decltype(m)>;
+ using Key = typename M::key_type;
+ m.try_emplace(m.begin(), Key{key_arg}, value_arg);
+ };
+ test_emplace_exception_guarantee(try_emplace_iter_rk);
+ }
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/try_emplace_transparent.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/try_emplace_transparent.pass.cpp
index 21fda43780967..abea83f956269 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/try_emplace_transparent.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/try_emplace_transparent.pass.cpp
@@ -65,7 +65,7 @@ static_assert(!CanTryEmplace<NonTransparentMap, TransparentMapConstIter, NonConv
static_assert(!CanTryEmplace<TransparentMap, TransparentMapConstIter, ConvertibleTransparent<int>, int>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -103,7 +103,7 @@ void test() {
assert(r3.first->second.get() == 5); // value
Moveable mv3(-1, 3.0);
- std::same_as<R> decltype(auto) r4 = m.try_emplace(ConvertibleTransparent<int>{117}, std::move(mv2));
+ std::same_as<R> decltype(auto) r4 = m.try_emplace(ConvertibleTransparent<int>{117}, std::move(mv3));
assert(m.size() == 13);
assert(r4.second); // was inserted
assert(mv2.moved()); // was moved from
@@ -136,9 +136,14 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<Moveable>>();
- test<std::deque<int>, std::vector<Moveable>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<Moveable>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<Moveable>>();
test<std::vector<int, min_allocator<int>>, std::vector<Moveable, min_allocator<Moveable>>>();
@@ -160,23 +165,34 @@ int main(int, char**) {
assert(p->second == 3);
assert(transparent_used);
}
- {
- auto try_emplace = [](auto& m, auto key_arg, auto value_arg) {
- using M = std::decay_t<decltype(m)>;
- using Key = typename M::key_type;
- m.try_emplace(ConvertibleTransparent<Key>{key_arg}, value_arg);
- };
- test_emplace_exception_guarantee(try_emplace);
- }
+ if (!std::is_constant_evaluated()) {
+ {
+ auto try_emplace = [](auto& m, auto key_arg, auto value_arg) {
+ using M = std::decay_t<decltype(m)>;
+ using Key = typename M::key_type;
+ m.try_emplace(ConvertibleTransparent<Key>{key_arg}, value_arg);
+ };
+ test_emplace_exception_guarantee(try_emplace);
+ }
- {
- auto try_emplace_iter = [](auto& m, auto key_arg, auto value_arg) {
- using M = std::decay_t<decltype(m)>;
- using Key = typename M::key_type;
- m.try_emplace(m.begin(), ConvertibleTransparent<Key>{key_arg}, value_arg);
- };
- test_emplace_exception_guarantee(try_emplace_iter);
+ {
+ auto try_emplace_iter = [](auto& m, auto key_arg, auto value_arg) {
+ using M = std::decay_t<decltype(m)>;
+ using Key = typename M::key_type;
+ m.try_emplace(m.begin(), ConvertibleTransparent<Key>{key_arg}, value_arg);
+ };
+ test_emplace_exception_guarantee(try_emplace_iter);
+ }
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.observers/comp.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.observers/comp.pass.cpp
index d86224952dee4..f85b7a08a464e 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.observers/comp.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.observers/comp.pass.cpp
@@ -16,12 +16,13 @@
#include <cassert>
#include <flat_map>
#include <functional>
+#include <type_traits>
#include <utility>
#include <vector>
#include "test_macros.h"
-int main(int, char**) {
+constexpr bool test() {
{
using M = std::flat_map<int, char>;
using Comp = std::less<int>; // the default
@@ -38,7 +39,7 @@ int main(int, char**) {
assert(vc({1, '2'}, {2, '1'}));
assert(!vc({2, '1'}, {1, '2'}));
}
- {
+ if (!std::is_constant_evaluated()) {
using Comp = std::function<bool(int, int)>;
using M = std::flat_map<int, int, Comp>;
Comp comp = std::greater<int>();
@@ -72,7 +73,7 @@ int main(int, char**) {
assert(vc({1, 2}, {2, 1}));
assert(!vc({2, 1}, {1, 2}));
}
- {
+ if (!std::is_constant_evaluated()) {
using Comp = std::function<bool(const std::vector<int>&, const std::vector<int>&)>;
using M = std::flat_map<std::vector<int>, int, Comp>;
Comp comp = [i = 1](const auto& x, const auto& y) { return x[i] < y[i]; };
@@ -92,5 +93,15 @@ int main(int, char**) {
assert(!vc(b, a));
assert(!vc(c, b));
}
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.observers/keys_values.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.observers/keys_values.pass.cpp
index 84d8f8344aaa6..dae2adf2b1e08 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.observers/keys_values.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.observers/keys_values.pass.cpp
@@ -28,7 +28,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -47,11 +47,25 @@ void test() {
assert(std::ranges::equal(values, expected_values));
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
- test<std::deque<int>, std::vector<char>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<char>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/contains.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/contains.pass.cpp
index 208d6138fa683..9b72aace59fc0 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/contains.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/contains.pass.cpp
@@ -23,7 +23,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
{
@@ -60,11 +60,25 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<int>>();
- test<std::deque<int>, std::vector<int>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<int>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<int>>();
test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/contains_transparent.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/contains_transparent.pass.cpp
index 0493538ab6dad..b47141be8bdaa 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/contains_transparent.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/contains_transparent.pass.cpp
@@ -34,7 +34,7 @@ static_assert(!CanContains<NonTransparentMap>);
static_assert(!CanContains<const NonTransparentMap>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -52,9 +52,14 @@ void test() {
assert(m.contains(Transparent<std::string>{"g"}) == false);
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<std::string>, std::vector<int>>();
- test<std::deque<std::string>, std::vector<int>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<std::string>, std::vector<int>>();
+ }
test<MinSequenceContainer<std::string>, MinSequenceContainer<int>>();
test<std::vector<std::string, min_allocator<std::string>>, std::vector<int, min_allocator<int>>>();
@@ -67,5 +72,15 @@ int main(int, char**) {
assert(b);
assert(transparent_used);
}
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/count.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/count.pass.cpp
index db675854d5e98..a79880ad26d28 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/count.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/count.pass.cpp
@@ -23,7 +23,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
@@ -59,11 +59,25 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<int>>();
- test<std::deque<int>, std::vector<int>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<int>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<int>>();
test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/count_transparent.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/count_transparent.pass.cpp
index cd195ff1fa8b4..6a63351941324 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/count_transparent.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/count_transparent.pass.cpp
@@ -34,7 +34,7 @@ static_assert(!CanCount<NonTransparentMap>);
static_assert(!CanCount<const NonTransparentMap>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -52,9 +52,14 @@ void test() {
assert(m.count(Transparent<std::string>{"g"}) == 0);
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<std::string>, std::vector<int>>();
- test<std::deque<std::string>, std::vector<int>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<std::string>, std::vector<int>>();
+ }
test<MinSequenceContainer<std::string>, MinSequenceContainer<int>>();
test<std::vector<std::string, min_allocator<std::string>>, std::vector<int, min_allocator<int>>>();
@@ -68,5 +73,14 @@ int main(int, char**) {
assert(transparent_used);
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/equal_range.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/equal_range.pass.cpp
index 8fa73d2a2eb51..e09516226e084 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/equal_range.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/equal_range.pass.cpp
@@ -24,7 +24,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
{
@@ -68,11 +68,25 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
- test<std::deque<int>, std::vector<char>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<char>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/equal_range_transparent.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/equal_range_transparent.pass.cpp
index 0198f433bdc4f..910d4ce8c9e90 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/equal_range_transparent.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/equal_range_transparent.pass.cpp
@@ -35,7 +35,7 @@ static_assert(!CanEqualRange<NonTransparentMap>);
static_assert(!CanEqualRange<const NonTransparentMap>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -80,9 +80,14 @@ void test() {
test_not_found(cm, "zzz", 5);
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<std::string>, std::vector<int>>();
- test<std::deque<std::string>, std::vector<int>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<std::string>, std::vector<int>>();
+ }
test<MinSequenceContainer<std::string>, MinSequenceContainer<int>>();
test<std::vector<std::string, min_allocator<std::string>>, std::vector<int, min_allocator<int>>>();
@@ -96,5 +101,14 @@ int main(int, char**) {
assert(transparent_used);
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/find.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/find.pass.cpp
index 9fae407c7d8f7..67e2f9213a1b6 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/find.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/find.pass.cpp
@@ -25,7 +25,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -45,11 +45,25 @@ void test() {
assert(std::as_const(m).find(9) == m.end());
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
- test<std::deque<int>, std::vector<char>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<char>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/find_transparent.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/find_transparent.pass.cpp
index 291577a89fc8f..e85194a15b394 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/find_transparent.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/find_transparent.pass.cpp
@@ -35,7 +35,7 @@ static_assert(!CanFind<NonTransparentMap>);
static_assert(!CanFind<const NonTransparentMap>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -68,9 +68,14 @@ void test() {
test_find(cm, "zzz", 5);
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<std::string>, std::vector<int>>();
- test<std::deque<std::string>, std::vector<int>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<std::string>, std::vector<int>>();
+ }
test<MinSequenceContainer<std::string>, MinSequenceContainer<int>>();
test<std::vector<std::string, min_allocator<std::string>>, std::vector<int, min_allocator<int>>>();
@@ -84,5 +89,14 @@ int main(int, char**) {
assert(transparent_used);
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/lower_bound.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/lower_bound.pass.cpp
index b5491f3b22674..cc7622ce556e7 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/lower_bound.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/lower_bound.pass.cpp
@@ -24,7 +24,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
{
@@ -61,11 +61,25 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
- test<std::deque<int>, std::vector<char>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<char>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/lower_bound_transparent.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/lower_bound_transparent.pass.cpp
index 6a923c197e91e..bd0316245620e 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/lower_bound_transparent.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/lower_bound_transparent.pass.cpp
@@ -35,7 +35,7 @@ static_assert(!CanLowerBound<NonTransparentMap>);
static_assert(!CanLowerBound<const NonTransparentMap>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -75,9 +75,14 @@ void test() {
test_lower_bound(cm, "zzz", 5);
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<std::string>, std::vector<int>>();
- test<std::deque<std::string>, std::vector<int>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<std::string>, std::vector<int>>();
+ }
test<MinSequenceContainer<std::string>, MinSequenceContainer<int>>();
test<std::vector<std::string, min_allocator<std::string>>, std::vector<int, min_allocator<int>>>();
@@ -91,5 +96,14 @@ int main(int, char**) {
assert(transparent_used);
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/upper_bound.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/upper_bound.pass.cpp
index 775e53286d629..13eb3b1d941b4 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/upper_bound.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/upper_bound.pass.cpp
@@ -24,7 +24,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
{
@@ -62,11 +62,25 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
- test<std::deque<int>, std::vector<char>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::vector<char>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/upper_bound_transparent.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/upper_bound_transparent.pass.cpp
index 4e83f920835df..110f9e8c151e8 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/upper_bound_transparent.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.operations/upper_bound_transparent.pass.cpp
@@ -35,7 +35,7 @@ static_assert(!CanUpperBound<NonTransparentMap>);
static_assert(!CanUpperBound<const NonTransparentMap>);
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -75,9 +75,14 @@ void test() {
test_upper_bound(cm, "zzz", 5);
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<std::string>, std::vector<int>>();
- test<std::deque<std::string>, std::vector<int>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<std::string>, std::vector<int>>();
+ }
test<MinSequenceContainer<std::string>, MinSequenceContainer<int>>();
test<std::vector<std::string, min_allocator<std::string>>, std::vector<int, min_allocator<int>>>();
{
@@ -90,5 +95,14 @@ int main(int, char**) {
assert(transparent_used);
}
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/helpers.h b/libcxx/test/std/containers/container.adaptors/flat.map/helpers.h
index b6b8fa061c840..932f330db829e 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/helpers.h
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/helpers.h
@@ -14,13 +14,14 @@
#include <string>
#include <vector>
#include <flat_map>
+#include <ranges>
#include "../flat_helpers.h"
#include "test_allocator.h"
#include "test_macros.h"
template <class... Args>
-void check_invariant(const std::flat_map<Args...>& m) {
+constexpr void check_invariant(const std::flat_map<Args...>& m) {
assert(m.keys().size() == m.values().size());
const auto& keys = m.keys();
assert(std::is_sorted(keys.begin(), keys.end(), m.key_comp()));
@@ -31,6 +32,14 @@ void check_invariant(const std::flat_map<Args...>& m) {
assert(std::adjacent_find(keys.begin(), keys.end(), key_equal) == keys.end());
}
+constexpr void check_possible_values(const auto& actual, const auto& expected) {
+ assert(std::ranges::size(actual) == std::ranges::size(expected));
+
+ for (const auto& [actual_value, possible_values] : std::views::zip(actual, expected)) {
+ assert(std::ranges::find(possible_values, actual_value) != std::ranges::end(possible_values));
+ }
+}
+
template <class F>
void test_emplace_exception_guarantee([[maybe_unused]] F&& emplace_function) {
#ifndef TEST_HAS_NO_EXCEPTIONS
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/incomplete_type.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/incomplete_type.pass.cpp
index 76461951f0d3d..80f4af4be44bc 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/incomplete_type.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/incomplete_type.pass.cpp
@@ -16,6 +16,8 @@
#include <flat_map>
#include <vector>
+#include "test_macros.h"
+
struct A {
using Map = std::flat_map<A, A>;
int data;
@@ -25,9 +27,20 @@ struct A {
};
// Implement the operator< required in order to instantiate flat_map<A, X>
-bool operator<(A const& L, A const& R) { return L.data < R.data; }
+constexpr bool operator<(A const& L, A const& R) { return L.data < R.data; }
-int main(int, char**) {
+
+constexpr bool test() {
A a;
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/op_compare.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/op_compare.pass.cpp
index fffe711580704..5d3110215c46a 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/op_compare.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/op_compare.pass.cpp
@@ -31,7 +31,7 @@
#include "test_container_comparisons.h"
template <class KeyContainer, class ValueContainer>
-void test() {
+constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
@@ -70,9 +70,14 @@ void test() {
}
}
-int main(int, char**) {
+constexpr bool test() {
test<std::vector<int>, std::vector<int>>();
- test<std::deque<int>, std::deque<int>>();
+#ifndef __cpp_lib_constexpr_deque
+ if (!std::is_constant_evaluated())
+#endif
+ {
+ test<std::deque<int>, std::deque<int>>();
+ }
test<MinSequenceContainer<int>, MinSequenceContainer<int>>();
test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
@@ -98,7 +103,7 @@ int main(int, char**) {
{
// Comparisons use value_type's native operators, not the comparator
struct StrongComp {
- bool operator()(double a, double b) const { return std::strong_order(a, b) < 0; }
+ constexpr bool operator()(double a, double b) const { return std::strong_order(a, b) < 0; }
};
using C = std::flat_map<double, double, StrongComp>;
C s1 = {{1, 1}};
@@ -114,5 +119,15 @@ int main(int, char**) {
assert(s1 != s2);
assert((s1 <=> s2) == std::partial_ordering::unordered);
}
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+#if TEST_STD_VER >= 26
+ static_assert(test());
+#endif
+
return 0;
}
diff --git a/libcxx/test/std/containers/container.adaptors/flat_helpers.h b/libcxx/test/std/containers/container.adaptors/flat_helpers.h
index 9cd408ef960a9..6db7ec6abba0b 100644
--- a/libcxx/test/std/containers/container.adaptors/flat_helpers.h
+++ b/libcxx/test/std/containers/container.adaptors/flat_helpers.h
@@ -18,18 +18,19 @@ struct CopyOnlyVector : std::vector<T> {
using std::vector<T>::vector;
CopyOnlyVector(const CopyOnlyVector&) = default;
- CopyOnlyVector(CopyOnlyVector&& other) : CopyOnlyVector(other) {}
- CopyOnlyVector(CopyOnlyVector&& other, std::vector<T>::allocator_type alloc) : CopyOnlyVector(other, alloc) {}
+ constexpr CopyOnlyVector(CopyOnlyVector&& other) : CopyOnlyVector(other) {}
+ constexpr CopyOnlyVector(CopyOnlyVector&& other, std::vector<T>::allocator_type alloc)
+ : CopyOnlyVector(other, alloc) {}
- CopyOnlyVector& operator=(const CopyOnlyVector&) = default;
- CopyOnlyVector& operator=(CopyOnlyVector& other) { return this->operator=(other); }
+ constexpr CopyOnlyVector& operator=(const CopyOnlyVector&) = default;
+ constexpr CopyOnlyVector& operator=(CopyOnlyVector& other) { return this->operator=(other); }
};
template <class T, bool ConvertibleToT = false>
struct Transparent {
T t;
- explicit operator T() const
+ TEST_CONSTEXPR explicit operator T() const
requires ConvertibleToT
{
return t;
@@ -50,10 +51,10 @@ struct TransparentComparator {
bool* transparent_used = nullptr;
TransparentComparator() = default;
- TransparentComparator(bool& used) : transparent_used(&used) {}
+ TEST_CONSTEXPR TransparentComparator(bool& used) : transparent_used(&used) {}
template <class T, bool Convertible>
- bool operator()(const T& t, const Transparent<T, Convertible>& transparent) const {
+ TEST_CONSTEXPR bool operator()(const T& t, const Transparent<T, Convertible>& transparent) const {
if (transparent_used != nullptr) {
*transparent_used = true;
}
@@ -61,7 +62,7 @@ struct TransparentComparator {
}
template <class T, bool Convertible>
- bool operator()(const Transparent<T, Convertible>& transparent, const T& t) const {
+ TEST_CONSTEXPR bool operator()(const Transparent<T, Convertible>& transparent, const T& t) const {
if (transparent_used != nullptr) {
*transparent_used = true;
}
@@ -69,7 +70,7 @@ struct TransparentComparator {
}
template <class T>
- bool operator()(const T& t1, const T& t2) const {
+ TEST_CONSTEXPR bool operator()(const T& t1, const T& t2) const {
return t1 < t2;
}
};
@@ -94,13 +95,13 @@ class Moveable {
double double_;
public:
- Moveable() : int_(0), double_(0) {}
- Moveable(int i, double d) : int_(i), double_(d) {}
- Moveable(Moveable&& x) : int_(x.int_), double_(x.double_) {
+ TEST_CONSTEXPR Moveable() : int_(0), double_(0) {}
+ TEST_CONSTEXPR Moveable(int i, double d) : int_(i), double_(d) {}
+ TEST_CONSTEXPR Moveable(Moveable&& x) : int_(x.int_), double_(x.double_) {
x.int_ = -1;
x.double_ = -1;
}
- Moveable& operator=(Moveable&& x) {
+ TEST_CONSTEXPR Moveable& operator=(Moveable&& x) {
int_ = x.int_;
x.int_ = -1;
double_ = x.double_;
@@ -110,11 +111,13 @@ class Moveable {
Moveable(const Moveable&) = delete;
Moveable& operator=(const Moveable&) = delete;
- bool operator==(const Moveable& x) const { return int_ == x.int_ && double_ == x.double_; }
- bool operator<(const Moveable& x) const { return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_); }
+ TEST_CONSTEXPR bool operator==(const Moveable& x) const { return int_ == x.int_ && double_ == x.double_; }
+ TEST_CONSTEXPR bool operator<(const Moveable& x) const {
+ return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);
+ }
- int get() const { return int_; }
- bool moved() const { return int_ == -1; }
+ TEST_CONSTEXPR int get() const { return int_; }
+ TEST_CONSTEXPR bool moved() const { return int_ == -1; }
};
#ifndef TEST_HAS_NO_EXCEPTIONS
diff --git a/libcxx/test/std/containers/test_compare.h b/libcxx/test/std/containers/test_compare.h
index 18e0b27dc954d..070f15869a4a3 100644
--- a/libcxx/test/std/containers/test_compare.h
+++ b/libcxx/test/std/containers/test_compare.h
@@ -9,22 +9,24 @@
#ifndef TEST_COMPARE_H
#define TEST_COMPARE_H
+#include "test_macros.h"
+
template <class T>
struct test_equal_to {
int data_;
- explicit test_equal_to() : data_(0) {}
- explicit test_equal_to(int data) : data_(data) {}
- bool operator()(const T& a, const T& b) const { return a == b; }
- friend bool operator==(const test_equal_to& a, const test_equal_to& b) { return a.data_ == b.data_; }
+ TEST_CONSTEXPR explicit test_equal_to() : data_(0) {}
+ TEST_CONSTEXPR explicit test_equal_to(int data) : data_(data) {}
+ TEST_CONSTEXPR bool operator()(const T& a, const T& b) const { return a == b; }
+ TEST_CONSTEXPR friend bool operator==(const test_equal_to& a, const test_equal_to& b) { return a.data_ == b.data_; }
};
template <class T>
struct test_less {
int data_;
- explicit test_less() : data_(0) {}
- explicit test_less(int data) : data_(data) {}
- bool operator()(const T& a, const T& b) const { return a < b; }
- friend bool operator==(const test_less& a, const test_less& b) { return a.data_ == b.data_; }
+ TEST_CONSTEXPR explicit test_less() : data_(0) {}
+ TEST_CONSTEXPR explicit test_less(int data) : data_(data) {}
+ TEST_CONSTEXPR bool operator()(const T& a, const T& b) const { return a < b; }
+ TEST_CONSTEXPR friend bool operator==(const test_less& a, const test_less& b) { return a.data_ == b.data_; }
};
#endif // TEST_COMPARE_H
diff --git a/libcxx/test/support/MinSequenceContainer.h b/libcxx/test/support/MinSequenceContainer.h
index 7fee4dd0fbdc1..a399146159278 100644
--- a/libcxx/test/support/MinSequenceContainer.h
+++ b/libcxx/test/support/MinSequenceContainer.h
@@ -13,6 +13,7 @@
#include <vector>
#include "test_iterators.h"
+#include "test_macros.h"
template <class T, class Iterator = random_access_iterator<T*>, class ConstIterator = random_access_iterator<const T*>>
struct MinSequenceContainer {
@@ -24,42 +25,46 @@ struct MinSequenceContainer {
explicit MinSequenceContainer() = default;
template <class It>
- explicit MinSequenceContainer(It first, It last) : data_(first, last) {}
- MinSequenceContainer(std::initializer_list<T> il) : data_(il) {}
- iterator begin() { return iterator(data_.data()); }
- const_iterator begin() const { return const_iterator(data_.data()); }
- const_iterator cbegin() const { return const_iterator(data_.data()); }
- iterator end() { return begin() + size(); }
- const_iterator end() const { return begin() + size(); }
- size_type size() const { return static_cast<size_type>(data_.size()); }
- bool empty() const { return data_.empty(); }
-
- void clear() { data_.clear(); }
+ TEST_CONSTEXPR_CXX23 explicit MinSequenceContainer(It first, It last) : data_(first, last) {}
+ TEST_CONSTEXPR_CXX23 MinSequenceContainer(std::initializer_list<T> il) : data_(il) {}
+ TEST_CONSTEXPR_CXX23 iterator begin() { return iterator(data_.data()); }
+ TEST_CONSTEXPR_CXX23 const_iterator begin() const { return const_iterator(data_.data()); }
+ TEST_CONSTEXPR_CXX23 const_iterator cbegin() const { return const_iterator(data_.data()); }
+ TEST_CONSTEXPR_CXX23 iterator end() { return begin() + size(); }
+ TEST_CONSTEXPR_CXX23 const_iterator end() const { return begin() + size(); }
+ TEST_CONSTEXPR_CXX23 size_type size() const { return static_cast<size_type>(data_.size()); }
+ TEST_CONSTEXPR_CXX23 bool empty() const { return data_.empty(); }
+
+ TEST_CONSTEXPR_CXX23 void clear() { data_.clear(); }
template <class It>
- iterator insert(const_iterator p, It first, It last) {
+ TEST_CONSTEXPR_CXX23 iterator insert(const_iterator p, It first, It last) {
return from_vector_iterator(data_.insert(to_vector_iterator(p), first, last));
}
- iterator insert(const_iterator p, T value) {
+ TEST_CONSTEXPR_CXX23 iterator insert(const_iterator p, T value) {
return from_vector_iterator(data_.insert(to_vector_iterator(p), std::move(value)));
}
- iterator erase(const_iterator first, const_iterator last) {
+ TEST_CONSTEXPR_CXX23 iterator erase(const_iterator first, const_iterator last) {
return from_vector_iterator(data_.erase(to_vector_iterator(first), to_vector_iterator(last)));
}
- iterator erase(const_iterator iter) { return from_vector_iterator(data_.erase(to_vector_iterator(iter))); }
+ TEST_CONSTEXPR_CXX23 iterator erase(const_iterator iter) {
+ return from_vector_iterator(data_.erase(to_vector_iterator(iter)));
+ }
template <class... Args>
- iterator emplace(const_iterator pos, Args&&... args) {
+ TEST_CONSTEXPR_CXX23 iterator emplace(const_iterator pos, Args&&... args) {
return from_vector_iterator(data_.emplace(to_vector_iterator(pos), std::forward<Args>(args)...));
}
private:
- std::vector<T>::const_iterator to_vector_iterator(const_iterator cit) const { return cit - cbegin() + data_.begin(); }
+ TEST_CONSTEXPR_CXX23 std::vector<T>::const_iterator to_vector_iterator(const_iterator cit) const {
+ return cit - cbegin() + data_.begin();
+ }
- iterator from_vector_iterator(std::vector<T>::iterator it) { return it - data_.begin() + begin(); }
+ TEST_CONSTEXPR_CXX23 iterator from_vector_iterator(std::vector<T>::iterator it) { return it - data_.begin() + begin(); }
std::vector<T> data_;
};
>From c66e76aba676046503531ee9d298e840c4eb962c Mon Sep 17 00:00:00 2001
From: Hui Xie <hui.xie1990 at gmail.com>
Date: Sat, 26 Apr 2025 11:11:31 +0100
Subject: [PATCH 2/5] clang format
---
.../flat.map/flat.map.access/index_key.pass.cpp | 1 -
.../flat.map/flat.map.cons/iter_iter.pass.cpp | 4 ++--
.../container.adaptors/flat.map/incomplete_type.pass.cpp | 1 -
libcxx/test/support/MinSequenceContainer.h | 4 +++-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/index_key.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/index_key.pass.cpp
index a7d613de399ed..149a459ea541e 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/index_key.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.access/index_key.pass.cpp
@@ -83,7 +83,6 @@ constexpr bool test() {
return true;
}
-
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp
index 812553ea0fa68..1a215e295333a 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp
@@ -101,8 +101,8 @@ constexpr void test() {
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test_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}};
+ 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}};
{
// flat_map(InputIterator , InputIterator, const Allocator&)
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/incomplete_type.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/incomplete_type.pass.cpp
index 80f4af4be44bc..d89e549b5fc23 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/incomplete_type.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/incomplete_type.pass.cpp
@@ -29,7 +29,6 @@ struct A {
// Implement the operator< required in order to instantiate flat_map<A, X>
constexpr bool operator<(A const& L, A const& R) { return L.data < R.data; }
-
constexpr bool test() {
A a;
diff --git a/libcxx/test/support/MinSequenceContainer.h b/libcxx/test/support/MinSequenceContainer.h
index a399146159278..04e29cc53e947 100644
--- a/libcxx/test/support/MinSequenceContainer.h
+++ b/libcxx/test/support/MinSequenceContainer.h
@@ -64,7 +64,9 @@ struct MinSequenceContainer {
return cit - cbegin() + data_.begin();
}
- TEST_CONSTEXPR_CXX23 iterator from_vector_iterator(std::vector<T>::iterator it) { return it - data_.begin() + begin(); }
+ TEST_CONSTEXPR_CXX23 iterator from_vector_iterator(std::vector<T>::iterator it) {
+ return it - data_.begin() + begin();
+ }
std::vector<T> data_;
};
>From e323ed152f1594f2ceee76ac467c0455477cedec Mon Sep 17 00:00:00 2001
From: Hui Xie <hui.xie1990 at gmail.com>
Date: Sat, 26 Apr 2025 15:28:23 +0100
Subject: [PATCH 3/5] ci
---
libcxx/include/module.modulemap.in | 3 +++
.../flat.map.modifiers/insert_initializer_list.pass.cpp | 1 -
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index af928a63f2315..3288f67d954a1 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -1304,6 +1304,9 @@ module std [system] {
header "flat_map"
export *
+ export std.algorithm.ranges_sort
+ export std.ranges.zip_view
+ export std.tuple
}
module flat_set {
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_initializer_list.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_initializer_list.pass.cpp
index 1a49e30584df0..ff6b2a9162cf3 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_initializer_list.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/insert_initializer_list.pass.cpp
@@ -29,7 +29,6 @@ constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
- using V = std::pair<const int, double>;
M m = {{1, 1}, {1, 1.5}, {1, 2}, {3, 1}, {3, 1.5}, {3, 2}};
m.insert({
>From ebf606b7e045a1b132f13b60acea59d7a6787263 Mon Sep 17 00:00:00 2001
From: Hui Xie <hui.xie1990 at gmail.com>
Date: Sat, 26 Apr 2025 16:54:03 +0100
Subject: [PATCH 4/5] ci
---
libcxx/test/std/containers/Emplaceable.h | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/libcxx/test/std/containers/Emplaceable.h b/libcxx/test/std/containers/Emplaceable.h
index 48d8eab0a9a09..512cbf5e34459 100644
--- a/libcxx/test/std/containers/Emplaceable.h
+++ b/libcxx/test/std/containers/Emplaceable.h
@@ -22,13 +22,13 @@ class Emplaceable {
double double_;
public:
- TEST_CONSTEXPR Emplaceable() : int_(0), double_(0) {}
- TEST_CONSTEXPR Emplaceable(int i, double d) : int_(i), double_(d) {}
- TEST_CONSTEXPR Emplaceable(Emplaceable&& x) : int_(x.int_), double_(x.double_) {
+ TEST_CONSTEXPR_CXX20 Emplaceable() : int_(0), double_(0) {}
+ TEST_CONSTEXPR_CXX20 Emplaceable(int i, double d) : int_(i), double_(d) {}
+ TEST_CONSTEXPR_CXX20 Emplaceable(Emplaceable&& x) : int_(x.int_), double_(x.double_) {
x.int_ = 0;
x.double_ = 0;
}
- TEST_CONSTEXPR Emplaceable& operator=(Emplaceable&& x) {
+ TEST_CONSTEXPR_CXX20 Emplaceable& operator=(Emplaceable&& x) {
int_ = x.int_;
x.int_ = 0;
double_ = x.double_;
@@ -36,12 +36,12 @@ class Emplaceable {
return *this;
}
- TEST_CONSTEXPR bool operator==(const Emplaceable& x) const { return int_ == x.int_ && double_ == x.double_; }
- TEST_CONSTEXPR bool operator<(const Emplaceable& x) const {
+ TEST_CONSTEXPR_CXX20 bool operator==(const Emplaceable& x) const { return int_ == x.int_ && double_ == x.double_; }
+ TEST_CONSTEXPR_CXX20 bool operator<(const Emplaceable& x) const {
return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);
}
- TEST_CONSTEXPR int get() const { return int_; }
+ TEST_CONSTEXPR_CXX20 int get() const { return int_; }
};
template <>
>From da7de434686f24b999c3d16db389d29261f7f375 Mon Sep 17 00:00:00 2001
From: Hui Xie <hui.xie1990 at gmail.com>
Date: Sat, 26 Apr 2025 19:48:29 +0100
Subject: [PATCH 5/5] ci
---
.../container.adaptors/flat.map/flat.map.cons/range.pass.cpp | 2 --
1 file changed, 2 deletions(-)
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp
index ae447f62b57d4..0b3cb800124f8 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp
@@ -284,10 +284,8 @@ constexpr bool test() {
}
test<std::vector<int>, std::vector<int>>();
- test<std::vector<int>, std::vector<double>>();
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
- test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
test_alloc<std::vector, std::vector>();
More information about the libcxx-commits
mailing list