[libc++] constexpr flat_map (#137453)

Fixes #128673
This commit is contained in:
Hui
2025-06-21 13:41:32 +01:00
committed by GitHub
parent 77941eba7f
commit 831fcb5e91
85 changed files with 2954 additions and 1482 deletions

View File

@@ -47,6 +47,7 @@ Implemented Papers
- P1222R4: A Standard ``flat_set`` (`Github <https://github.com/llvm/llvm-project/issues/105193>`__)
- P2897R7: ``aligned_accessor``: An mdspan accessor expressing pointer over-alignment (`Github <https://github.com/llvm/llvm-project/issues/118372>`__)
- P3247R2: Deprecate the notion of trivial types (`Github <https://github.com/llvm/llvm-project/issues/118387>`__)
- P3372R3: ``constexpr`` containers and adaptors (`Github <https://github.com/llvm/llvm-project/issues/128673>`__) (Only ``constexpr flat_map`` is implemented)
- P2441R2: ``views::join_with`` (`Github <https://github.com/llvm/llvm-project/issues/105185>`__)
- P2711R1: Making multi-param constructors of ``views`` ``explicit`` (`Github <https://github.com/llvm/llvm-project/issues/105252>`__)
- P2770R0: Stashing stashing ``iterators`` for proper flattening (`Github <https://github.com/llvm/llvm-project/issues/105250>`__)

View File

@@ -104,7 +104,7 @@
"`P3137R3 <https://wg21.link/P3137R3>`__","``views::to_input``","2025-02 (Hagenberg)","","",""
"`P0472R3 <https://wg21.link/P0472R3>`__","Put ``std::monostate`` in ``<utility>``","2025-02 (Hagenberg)","|Complete|","21",""
"`P3349R1 <https://wg21.link/P3349R1>`__","Converting contiguous iterators to pointers","2025-02 (Hagenberg)","","",""
"`P3372R3 <https://wg21.link/P3372R3>`__","constexpr containers and adaptors","2025-02 (Hagenberg)","","",""
"`P3372R3 <https://wg21.link/P3372R3>`__","constexpr containers and adaptors","2025-02 (Hagenberg)","|In Progress|","",""
"`P3378R2 <https://wg21.link/P3378R2>`__","constexpr exception types","2025-02 (Hagenberg)","","",""
"`P3441R2 <https://wg21.link/P3441R2>`__","Rename ``simd_split`` to ``simd_chunk``","2025-02 (Hagenberg)","","",""
"`P3287R3 <https://wg21.link/P3287R3>`__","Exploration of namespaces for ``std::simd``","2025-02 (Hagenberg)","","",""
1 Paper # Paper Name Meeting Status First released version Notes
104 `P3137R3 <https://wg21.link/P3137R3>`__ ``views::to_input`` 2025-02 (Hagenberg)
105 `P0472R3 <https://wg21.link/P0472R3>`__ Put ``std::monostate`` in ``<utility>`` 2025-02 (Hagenberg) |Complete| 21
106 `P3349R1 <https://wg21.link/P3349R1>`__ Converting contiguous iterators to pointers 2025-02 (Hagenberg)
107 `P3372R3 <https://wg21.link/P3372R3>`__ constexpr containers and adaptors 2025-02 (Hagenberg) |In Progress|
108 `P3378R2 <https://wg21.link/P3378R2>`__ constexpr exception types 2025-02 (Hagenberg)
109 `P3441R2 <https://wg21.link/P3441R2>`__ Rename ``simd_split`` to ``simd_chunk`` 2025-02 (Hagenberg)
110 `P3287R3 <https://wg21.link/P3287R3>`__ Exploration of namespaces for ``std::simd`` 2025-02 (Hagenberg)

View File

@@ -114,11 +114,12 @@ public:
class value_compare {
private:
_LIBCPP_NO_UNIQUE_ADDRESS 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);
}
};
@@ -137,14 +138,14 @@ private:
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
@@ -165,7 +166,7 @@ public:
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,
@@ -174,7 +175,7 @@ public:
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
@@ -191,7 +192,7 @@ public:
# 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(),
@@ -201,7 +202,7 @@ public:
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(),
@@ -211,7 +212,7 @@ public:
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,
@@ -222,7 +223,7 @@ public:
__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,
@@ -236,7 +237,7 @@ public:
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,
@@ -250,12 +251,12 @@ public:
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");
@@ -263,21 +264,22 @@ public:
__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);
@@ -285,7 +287,7 @@ public:
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);
@@ -293,99 +295,105 @@ public:
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
@@ -402,49 +410,65 @@ public:
}
// 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;
@@ -453,11 +477,11 @@ public:
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");
@@ -465,7 +489,7 @@ public:
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");
@@ -475,7 +499,7 @@ public:
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");
@@ -485,7 +509,7 @@ public:
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");
@@ -496,45 +520,49 @@ public:
// [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);
}
@@ -543,7 +571,8 @@ public:
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);
}
@@ -552,7 +581,7 @@ public:
}
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));
}
@@ -560,19 +589,22 @@ public:
__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");
@@ -586,13 +618,15 @@ public:
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)...);
}
@@ -600,75 +634,84 @@ public:
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);
@@ -680,14 +723,14 @@ public:
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_);
@@ -695,7 +738,7 @@ public:
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.
@@ -705,133 +748,156 @@ public:
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); }
template <class _Kp>
requires __is_compare_transparent
_LIBCPP_HIDE_FROM_ABI iterator find(const _Kp& __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 const_iterator find(const _Kp& __x) const {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 iterator find(const _Kp& __x) {
return __find_impl(*this, __x);
}
_LIBCPP_HIDE_FROM_ABI 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 const_iterator find(const _Kp& __x) const {
return __find_impl(*this, __x);
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 size_type count(const key_type& __x) const {
return contains(__x) ? 1 : 0;
}
_LIBCPP_HIDE_FROM_ABI 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 size_type count(const _Kp& __x) const {
return contains(__x) ? 1 : 0;
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool contains(const key_type& __x) const {
return find(__x) != end();
}
_LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __x) { return __lower_bound<iterator>(*this, __x); }
template <class _Kp>
requires __is_compare_transparent
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool contains(const _Kp& __x) const {
return find(__x) != end();
}
_LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __x) const {
_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 _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>(
@@ -840,12 +906,13 @@ private:
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);
}
@@ -853,7 +920,7 @@ private:
// 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();
@@ -863,14 +930,16 @@ private:
}
template <class _Self, class _KeyIter>
_LIBCPP_HIDE_FROM_ABI static auto __corresponding_mapped_it(_Self&& __self, _KeyIter&& __key_iter) {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 static auto
__corresponding_mapped_it(_Self&& __self, _KeyIter&& __key_iter) {
return __self.__containers_.values.begin() +
static_cast<ranges::range_difference_t<mapped_container_type>>(
ranges::distance(__self.__containers_.keys.begin(), __key_iter));
}
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) {
@@ -898,7 +967,7 @@ private:
}
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)) {
@@ -908,7 +977,7 @@ private:
}
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 =
std::lower_bound(__self.__containers_.keys.begin(), __self.__containers_.keys.end(), __key, __self.__compare_);
auto __last = __self.__containers_.keys.end();
@@ -919,7 +988,7 @@ private:
}
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);
using __iterator_type = ranges::iterator_t<decltype(__self)>;
return std::make_pair(__iterator_type(__key_first, __corresponding_mapped_it(__self, __key_first)),
@@ -927,7 +996,7 @@ private:
}
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) {
auto __key_iter =
std::lower_bound(__self.__containers_.keys.begin(), __self.__containers_.keys.end(), __x, __self.__compare_);
auto __mapped_iter = __corresponding_mapped_it(__self, __key_iter);
@@ -935,7 +1004,7 @@ private:
}
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) {
auto __key_iter =
std::upper_bound(__self.__containers_.keys.begin(), __self.__containers_.keys.end(), __x, __self.__compare_);
auto __mapped_iter = __corresponding_mapped_it(__self, __key_iter);
@@ -943,7 +1012,8 @@ private:
}
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 = std::lower_bound(__containers_.keys.begin(), __containers_.keys.end(), __key, __compare_);
auto __mapped_it = __containers_.values.begin() + ranges::distance(__containers_.keys.begin(), __key_it);
@@ -962,7 +1032,7 @@ private:
}
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;
}
@@ -973,7 +1043,8 @@ private:
}
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(
@@ -994,7 +1065,8 @@ private:
}
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);
@@ -1003,7 +1075,8 @@ private:
}
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);
@@ -1011,7 +1084,7 @@ private:
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 (__container_traits<_KeyContainer>::__reservable) {
__containers_.keys.reserve(__size);
}
@@ -1022,7 +1095,8 @@ private:
}
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);
@@ -1032,7 +1106,8 @@ private:
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;
@@ -1040,8 +1115,9 @@ private:
_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_;
@@ -1164,8 +1240,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();

View File

@@ -46,7 +46,7 @@ private:
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 @@ public:
_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_);
}

View File

@@ -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) {

View File

@@ -1298,6 +1298,9 @@ module std [system] {
header "flat_map"
export *
export std.algorithm.ranges_sort
export std.ranges.zip_view
export std.tuple
}
module flat_set {

View File

@@ -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_CXX14 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_CXX14 Emplaceable& operator=(Emplaceable&& x) {
TEST_CONSTEXPR_CXX20 Emplaceable& operator=(Emplaceable&& x) {
int_ = x.int_;
x.int_ = 0;
double_ = x.double_;
@@ -36,12 +36,12 @@ public:
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 <>
@@ -49,7 +49,7 @@ struct std::hash<Emplaceable> {
typedef Emplaceable argument_type;
typedef std::size_t result_type;
TEST_CONSTEXPR std::size_t operator()(const Emplaceable& x) const { return static_cast<std::size_t>(x.get()); }
TEST_CONSTEXPR_CXX20 std::size_t operator()(const Emplaceable& x) const { return static_cast<std::size_t>(x.get()); }
};
#endif // TEST_STD_VER >= 11

View File

@@ -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 (!TEST_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 (!TEST_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 (!TEST_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;
}

View File

@@ -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 (!TEST_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 (!TEST_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 (!TEST_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>>>();
{
@@ -114,5 +123,14 @@ int main(int, char**) {
assert(x == 1);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -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 (!TEST_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 (!TEST_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,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;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -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 (!TEST_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);
@@ -101,7 +107,8 @@ int main(int, char**) {
int& x = m["alpha"];
assert(x == 1);
}
{
if (!TEST_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;
@@ -110,5 +117,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;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -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;
}

View File

@@ -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 = TEST_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 (!TEST_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;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -20,11 +20,73 @@
#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 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>>);
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<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));
}
}
// 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, KeyContainer<int, A1>, ValueContainer<short, A2>>(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));
}
{
// explicit(false)
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() {
{
// The constructors in this subclause shall not participate in overload
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
@@ -41,53 +103,31 @@ int main(int, char**) {
static_assert(!std::is_constructible_v<M2, const C&, const A2&>);
static_assert(!std::is_constructible_v<M3, const C&, const A2&>);
}
{
using C = test_less<int>;
auto m = std::flat_map<int, char*, 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*>>);
}
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 (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
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));
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));
}
{
// 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)};
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));
}
{
// 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>);
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;
}

View File

@@ -30,18 +30,162 @@
#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**) {
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, 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};
assert(m2 == m);
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() == 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 = 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;
vs.push_back(3);
vs.push_back(2);
vs.push_back(1);
auto m = M(std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert(std::ranges::equal(m, expected, std::equal_to<>()));
}
{
// 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>, 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
assert((m == M{{1, 1}, {2, 2}, {3, 3}}));
assert(m.keys().get_allocator() == A(5));
assert(m.values().get_allocator() == A(6));
}
{
// flat_map(key_container_type , mapped_container_type, key_compare)
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)
M m2 = {ks, vs, C(4)};
assert(m2 == m);
assert(m2.key_comp() == C(4));
}
{
// 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>, 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
assert((m == M{{1, 1}, {2, 2}, {3, 3}}));
assert(m.keys().get_allocator() == A(4));
assert(m.values().get_allocator() == A(4));
}
{
// 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>, 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
assert((m == M{{1, 1}, {2, 2}, {3, 3}}));
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>;
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, 1, 1, 2, 2, 3, 2, 3, 3};
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}));
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));
// explicit(false)
M m2 = {ks, vs, C(4), A(5)};
assert(m2 == m);
assert(m2.key_comp() == C(4));
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
@@ -65,120 +209,25 @@ int main(int, char**) {
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&>);
}
{
// 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}));
// explicit(false)
M m2 = {ks, vs};
assert(m2 == m);
test<std::vector, std::vector>();
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}));
}
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
// 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 M = std::flat_map<int, MoveOnly, std::greater<int>, Ks, Vs>;
Ks ks = {1, 3, 2};
Vs vs;
vs.push_back(3);
vs.push_back(2);
vs.push_back(1);
auto m = M(std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert(std::ranges::equal(m, expected, std::equal_to<>()));
test<std::deque, std::vector>();
test<std::deque, std::deque>();
}
{
// 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));
auto m = M(std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m == M{{1, 1}, {2, 2}, {3, 3}}));
assert(m.keys().get_allocator() == A(5));
assert(m.values().get_allocator() == A(6));
}
{
// 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}));
assert(m.key_comp() == C(4));
// explicit(false)
M m2 = {ks, vs, C(4)};
assert(m2 == m);
assert(m2.key_comp() == C(4));
}
{
// 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));
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
assert((m == M{{1, 1}, {2, 2}, {3, 3}}));
assert(m.keys().get_allocator() == A(4));
assert(m.values().get_allocator() == A(4));
}
{
// 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));
M m = {ks, vs, A(4)}; // implicit ctor
assert(!ks.empty()); // it was an lvalue above
assert(!vs.empty()); // it was an lvalue above
assert((m == M{{1, 1}, {2, 2}, {3, 3}}));
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>;
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, 1, 1, 2, 2, 3, 2, 3, 3};
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}));
assert(m.key_comp() == C(4));
assert(m.keys().get_allocator() == A(5));
assert(m.values().get_allocator() == A(5));
return true;
}
// explicit(false)
M m2 = {ks, vs, C(4), A(5)};
assert(m2 == m);
assert(m2.key_comp() == C(4));
assert(m2.keys().get_allocator() == A(5));
assert(m2.values().get_allocator() == A(5));
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -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&>);
}
test<std::vector, std::vector>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
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));
// 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));
test<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -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;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -30,12 +30,84 @@
#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**) {
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>);
using M = std::flat_map<int, short>;
std::initializer_list<std::pair<int, short>> il = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
M m(il);
assert(std::equal(m.begin(), m.end(), expected, expected + 4));
}
{
// flat_map(initializer_list<value_type>);
// explicit(false)
using M = std::flat_map<int, short>;
M m = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
assert(std::equal(m.begin(), m.end(), expected, expected + 4));
}
{
// flat_map(initializer_list<value_type>);
using M = std::flat_map<int, short, std::greater<int>, 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>;
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&);
using C = test_less<int>;
using M = std::flat_map<int, short, C>;
auto m = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10));
assert(std::equal(m.begin(), m.end(), expected, expected + 4));
assert(m.key_comp() == C(10));
// explicit(false)
M m2 = {{{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10)};
assert(m2 == m);
assert(m2.key_comp() == C(10));
}
if (!TEST_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)>, 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);
}
{
// 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>, 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
@@ -82,76 +154,23 @@ int main(int, char**) {
!std::is_constructible_v<M, std::initializer_list<std::pair<const int, const short>>, std::allocator<int>>);
}
std::pair<int, short> expected[] = {{1, 1}, {2, 2}, {3, 3}, {5, 2}};
{
// flat_map(initializer_list<value_type>);
using M = std::flat_map<int, short>;
std::initializer_list<std::pair<int, short>> il = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
M m(il);
assert(std::equal(m.begin(), m.end(), expected, expected + 4));
}
{
// flat_map(initializer_list<value_type>);
// explicit(false)
using M = std::flat_map<int, short>;
M m = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
assert(std::equal(m.begin(), m.end(), expected, expected + 4));
}
{
// flat_map(initializer_list<value_type>);
using M = std::flat_map<int, short, std::greater<int>, std::deque<int, min_allocator<int>>>;
M m = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
}
{
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));
}
}
{
// flat_map(initializer_list<value_type>, const key_compare&);
using C = test_less<int>;
using M = std::flat_map<int, short, C>;
auto m = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10));
assert(std::equal(m.begin(), m.end(), expected, expected + 4));
assert(m.key_comp() == C(10));
test<std::vector, std::vector>();
// explicit(false)
M m2 = {{{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10)};
assert(m2 == m);
assert(m2.key_comp() == C(10));
}
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
// flat_map(initializer_list<value_type>, const key_compare&);
// Sorting uses the comparator that was passed in
using M = std::flat_map<int, short, std::function<bool(int, int)>, std::deque<int, min_allocator<int>>>;
auto m = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, std::greater<int>());
assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
assert(m.key_comp()(2, 1) == true);
}
{
// 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>>;
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));
test<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -22,14 +22,163 @@
#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**) {
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<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(), 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)};
assert(m2 == m);
}
{
// flat_map(InputIterator , InputIterator)
// greater
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(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<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<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(), 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)
M m2 = {ar, ar + 9, C(3)};
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>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
auto m = M(ar, ar + 9, A1(5));
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));
}
{
// flat_map(InputIterator , InputIterator, const Allocator&)
// explicit(false)
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>>;
M m = {ar, ar + 9, A1(5)}; // implicit ctor
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));
}
{
// flat_map(InputIterator , InputIterator, 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(ar, ar + 9, C(3), A1(5));
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));
}
{
// flat_map(InputIterator , InputIterator, const key_compare&, const Allocator&)
// explicit(false)
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>>;
M m = {ar, ar + 9, {}, A2(5)}; // implicit ctor
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
@@ -57,98 +206,30 @@ int main(int, char**) {
static_assert(!std::is_constructible_v<M3, Iter3, Iter3, const C&, const A2&>);
}
using P = std::pair<int, short>;
P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
P expected[] = {{1, 1}, {2, 4}, {3, 6}};
{
// flat_map(InputIterator , InputIterator)
// cpp17_input_iterator
using M = std::flat_map<int, short>;
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));
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>>>();
// explicit(false)
M m2 = {cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 9)};
assert(m2 == m);
}
{
// flat_map(InputIterator , InputIterator)
// greater
using M = std::flat_map<int, short, std::greater<int>, std::deque<int, min_allocator<int>>, std::deque<short>>;
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}));
}
{
// 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>>>;
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>>;
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(m.key_comp() == C(3));
test_alloc<std::vector, std::vector>();
// explicit(false)
M m2 = {ar, ar + 9, C(3)};
assert(m2 == m);
assert(m2.key_comp() == C(3));
}
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
// 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>>;
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(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(InputIterator , InputIterator, const Allocator&)
// 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>>;
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(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(InputIterator , InputIterator, 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(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(m.key_comp() == C(3));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(InputIterator , InputIterator, const key_compare&, const Allocator&)
// 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>>;
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(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
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;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -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());
}
}
constexpr bool test() {
test<std::vector, std::vector>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_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;
}
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -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;
}

View File

@@ -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,7 +68,171 @@ 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**) {
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<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(), 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)))};
assert(m2 == m);
}
{
// flat_map(from_range_t, R&&)
// greater
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(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<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(), 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<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(), 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)
M m2 = {std::from_range, R(ar, ar + 9), C(3)};
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>, 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(), 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));
}
{
// flat_map(from_range_t, R&&, const Allocator&)
// explicit(false)
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>>;
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(), 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));
}
{
// flat_map(from_range_t, R&&, 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>>;
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(), 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));
}
{
// flat_map(from_range_t, R&&, const key_compare&, const Allocator&)
// explicit(false)
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>>;
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(), 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
@@ -117,111 +283,28 @@ int main(int, char**) {
static_assert(!std::is_constructible_v<M, std::from_range_t, std::vector<NonPairLike>&, const C&, const A1&>);
}
using P = std::pair<int, short>;
P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
P expected[] = {{1, 1}, {2, 4}, {3, 6}};
{
// flat_map(from_range_t, R&&)
// input_range && !common
using M = std::flat_map<int, short>;
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));
test<std::vector<int>, std::vector<int>>();
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
// explicit(false)
M m2 = {std::from_range, R(Iter(ar), Sent(Iter(ar + 9)))};
assert(m2 == m);
}
{
// 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 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}));
}
{
// flat_map(from_range_t, R&&)
// contiguous range
using M = std::flat_map<int, short>;
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));
}
{
// 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 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(m.key_comp() == C(3));
test_alloc<std::vector, std::vector>();
// explicit(false)
M m2 = {std::from_range, R(ar, ar + 9), C(3)};
assert(m2 == m);
assert(m2.key_comp() == C(3));
}
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
// 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 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(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(from_range_t, R&&, const Allocator&)
// 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 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(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(from_range_t, R&&, 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>>;
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(m.key_comp() == C(3));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(from_range_t, R&&, const key_compare&, const Allocator&)
// 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 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(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
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;
}

View File

@@ -31,9 +31,117 @@
#include "test_allocator.h"
#include "test_iterators.h"
#include "test_macros.h"
#include "../helpers.h"
#include "../../../test_compare.h"
int main(int, char**) {
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test() {
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type)
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}}));
m = M(std::sorted_unique, std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
// explicit(false)
M m2 = {std::sorted_unique, std::move(ks2), std::move(vs2)};
assert(m == m2);
}
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type)
// non-default container, comparator and allocator type
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};
auto m = M(std::sorted_unique, ks, vs);
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
m = M(std::sorted_unique, std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
}
{
// 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>, 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
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert(m.keys().get_allocator() == A(4));
assert(m.values().get_allocator() == A(5));
}
{
// 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, 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}}));
assert(m.key_comp() == C(4));
// explicit(false)
M m2 = {std::sorted_unique, ks, vs, C(4)};
assert(m2 == m);
assert(m2.key_comp() == C(4));
}
{
// 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, 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));
assert(m.values().get_allocator() == A(5));
// explicit(false)
M m2 = {ks, vs, C(4), A(5)};
assert(m2 == m);
assert(m2.key_comp() == C(4));
assert(m2.keys().get_allocator() == A(5));
assert(m2.values().get_allocator() == A(5));
}
{
// 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>, 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
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert(m.keys().get_allocator() == A(6));
assert(m.values().get_allocator() == A(6));
// explicit(false)
M m2 = {std::sorted_unique, ks, vs, A(6)};
assert(m2 == m);
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
@@ -57,109 +165,25 @@ int main(int, char**) {
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&>);
}
{
// 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;
auto m = M(std::sorted_unique, ks, vs);
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
m = M(std::sorted_unique, std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
test<std::vector, std::vector>();
// explicit(false)
M m2 = {std::sorted_unique, std::move(ks2), std::move(vs2)};
assert(m == m2);
}
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
// 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 M = std::flat_map<int, char, std::greater<int>, Ks, Vs>;
Ks ks = {10, 4, 2, 1};
Vs vs = {1, 2, 3, 4};
auto m = M(std::sorted_unique, ks, vs);
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
m = M(std::sorted_unique, std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
test<std::deque, std::vector>();
test<std::deque, std::deque>();
}
{
// 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));
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
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert(m.keys().get_allocator() == A(4));
assert(m.values().get_allocator() == A(5));
}
{
// 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};
auto m = M(std::sorted_unique, ks, vs, C(4));
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert(m.key_comp() == C(4));
return true;
}
// explicit(false)
M m2 = {std::sorted_unique, ks, vs, C(4)};
assert(m2 == m);
assert(m2.key_comp() == C(4));
}
{
// 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));
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert(m.key_comp() == C(4));
assert(m.keys().get_allocator() == A(5));
assert(m.values().get_allocator() == A(5));
// explicit(false)
M m2 = {ks, vs, C(4), A(5)};
assert(m2 == m);
assert(m2.key_comp() == C(4));
assert(m2.keys().get_allocator() == A(5));
assert(m2.values().get_allocator() == A(5));
}
{
// 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));
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
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert(m.keys().get_allocator() == A(6));
assert(m.values().get_allocator() == A(6));
// explicit(false)
M m2 = {std::sorted_unique, ks, vs, A(6)};
assert(m2 == m);
assert(m2.keys().get_allocator() == A(6));
assert(m2.values().get_allocator() == A(6));
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -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 (!TEST_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);
test<std::vector, std::vector>();
// explicit(false)
M m2 = {std::sorted_unique, il1};
assert(m2 == m);
}
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
// 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::deque, std::deque>();
}
// 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>, 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}}));
}
{
// 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));
return true;
}
// 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));
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -20,15 +20,141 @@
#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**) {
template <class KeyContainer, class ValueContainer>
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
{
// flat_map(sorted_unique_t, InputIterator, InputIterator);
// cpp17_input_iterator
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}};
assert(m == expected);
// explicit(false)
M m2 = {std::sorted_unique, cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 4)};
assert(m2 == m);
}
{
// flat_map(sorted_unique_t, InputIterator, InputIterator);
// contiguous iterator
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 (!TEST_IS_CONSTANT_EVALUATED) {
// flat_map(sorted_unique_t, InputIterator, InputIterator, const key_compare&);
// cpp_17_input_iterator
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),
cpp17_input_iterator<const P*>(ar + 4),
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,
cpp17_input_iterator<const P*>(ar),
cpp17_input_iterator<const P*>(ar + 4),
std::less<int>()};
assert(m2 == m);
}
{
// flat_map(sorted_unique_t, InputIterator, InputIterator, const key_compare&);
// greater
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),
cpp17_input_iterator<const P*>(ar + 4),
std::greater<int>());
assert((m == M{{5, 5}, {4, 4}, {2, 2}, {1, 1}}));
}
{
// flat_map(sorted_unique_t, InputIterator, InputIterator, const key_compare&);
// contiguous iterator
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>, 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));
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, ar, ar + 4, A1(5)};
assert(m2 == m);
assert(m2.keys().get_allocator() == A1(5));
assert(m2.values().get_allocator() == A2(5));
}
{
// flat_map(sorted_unique_t, InputIterator, InputIterator, 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>>;
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));
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, InputIterator, InputIterator, 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>>;
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
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
@@ -54,118 +180,31 @@ int main(int, char**) {
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>;
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}};
assert(m == expected);
// explicit(false)
M m2 = {std::sorted_unique, cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 4)};
assert(m2 == m);
}
{
// 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}};
assert(m == expected);
}
{
// 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>;
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),
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<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>>>();
// explicit(false)
M m2 = {std::sorted_unique,
cpp17_input_iterator<const P*>(ar),
cpp17_input_iterator<const P*>(ar + 4),
std::less<int>()};
assert(m2 == m);
}
{
// 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>;
P ar[] = {{5, 5}, {4, 4}, {2, 2}, {1, 1}};
auto m = M(std::sorted_unique,
cpp17_input_iterator<const P*>(ar),
cpp17_input_iterator<const P*>(ar + 4),
std::greater<int>());
assert((m == M{{5, 5}, {4, 4}, {2, 2}, {1, 1}}));
}
{
// 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));
assert(m.empty());
assert(m.key_comp() == C(5));
}
{
// 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 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));
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));
test_alloc<std::vector, std::vector>();
// explicit(false)
M m2 = {std::sorted_unique, ar, ar + 4, A1(5)};
assert(m2 == m);
assert(m2.keys().get_allocator() == A1(5));
assert(m2.values().get_allocator() == A2(5));
}
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
// flat_map(sorted_unique_t, InputIterator, InputIterator, 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>>;
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));
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, InputIterator, InputIterator, 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>>;
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
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));
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;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -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>;
@@ -142,11 +142,25 @@ void test() {
assert(cri2 <=> cri1 == std::strong_ordering::greater);
}
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 (!TEST_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;
}

View File

@@ -25,48 +25,64 @@
#include <iterator>
#include "MinSequenceContainer.h"
#include "test_macros.h"
#include "min_allocator.h"
int main(int, char**) {
{
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());
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 (!TEST_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>>>();
{
// 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;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -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 (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
test_emplaceable<std::deque<int>, std::vector<Emplaceable>>();
}
if (!TEST_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;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -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 (!TEST_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 (!TEST_IS_CONSTANT_EVALUATED) {
auto erase_transparent = [](auto& m, auto key_arg) {
using Map = std::decay_t<decltype(m)>;
using Key = typename Map::key_type;
@@ -147,5 +153,14 @@ int main(int, char**) {
assert(n == 1);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -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,11 +25,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_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({
@@ -42,20 +43,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 (!TEST_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 (!TEST_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 +74,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;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -38,7 +38,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>;
@@ -68,22 +68,45 @@ 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);
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{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 m2 = m;
m2.insert(cpp17_input_iterator<P*>(ar2), cpp17_input_iterator<P*>(ar2 + sizeof(ar2) / sizeof(ar2[0])));
assert(m2.size() == 5);
assert(std::ranges::equal(m2.keys(), KeyContainer{0, 1, 2, 3, 4}));
check_possible_values(
m2.values(),
std::vector<std::vector<double>>{
{1, 1.5, 2},
{m[1]},
{m[2]},
{m[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 (!TEST_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 (!TEST_IS_CONSTANT_EVALUATED) {
auto insert_func = [](auto& m, const auto& newValues) { m.insert(newValues.begin(), newValues.end()); };
test_insert_range_exception_guarantee(insert_func);
}
@@ -94,5 +117,14 @@ int main(int, char**) {
assert(std::ranges::equal(m, std::vector<std::pair<int, int>>{{1, 1}, {2, 2}, {3, 3}, {4, 4}}));
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -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 (!TEST_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,22 +242,24 @@ 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 (!TEST_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);
}
}
{
// LWG4239 std::string and C string literal
@@ -267,5 +274,14 @@ int main(int, char**) {
assert(it2->second == 2);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -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;
}
};
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>;
const std::pair<int, int> expected[] = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}};
constexpr bool test() {
{
// insert(P&&)
// 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);
std::same_as<std::pair<typename M::iterator, bool>> decltype(auto) res =
m.insert(std::pair(ConvertibleTransparent<int>{3}, 3));
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));
assert(!transparent_used);
}
{
// 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));
}
{
// 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,26 @@ 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 (!TEST_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);
}
}
{
// LWG4239 std::string and C string literal
@@ -173,5 +120,15 @@ int main(int, char**) {
auto it2 = m.insert(m.begin(), {"beta2", 2});
assert(it2 == m.begin() + 2);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -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 (!TEST_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 (!TEST_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_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_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);
}
return true;
}
{
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);
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// gcc 15 ICE on this test
// UNSUPPORTED: gcc
// <flat_map>
@@ -65,7 +67,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 +105,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 +138,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 (!TEST_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>>>();
@@ -171,23 +178,34 @@ int main(int, char**) {
auto it2 = m.try_emplace(m.begin(), "beta2", 2);
assert(it2 == m.begin() + 2);
}
{
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 (!TEST_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;
}

View File

@@ -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 (!TEST_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 (!TEST_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;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -35,7 +35,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>;
@@ -53,9 +53,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 (!TEST_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>>>();
@@ -75,5 +80,15 @@ int main(int, char**) {
assert(m.contains("beta") == true);
assert(m.contains("charlie") == false);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -35,7 +35,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>;
@@ -53,9 +53,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 (!TEST_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>>>();
@@ -76,5 +81,14 @@ int main(int, char**) {
assert(m.count("charlie") == 0);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -36,7 +36,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>;
@@ -81,9 +81,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 (!TEST_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>>>();
@@ -105,5 +110,14 @@ int main(int, char**) {
assert(last == m.begin() + 2);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -36,7 +36,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>;
@@ -69,9 +69,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 (!TEST_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>>>();
@@ -92,5 +97,14 @@ int main(int, char**) {
assert(it == m.begin() + 1);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -36,7 +36,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>;
@@ -76,9 +76,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 (!TEST_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>>>();
@@ -99,5 +104,14 @@ int main(int, char**) {
assert(it == m.begin() + 2);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -36,7 +36,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>;
@@ -76,9 +76,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 (!TEST_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>>>();
{
@@ -98,5 +103,14 @@ int main(int, char**) {
assert(it == m.begin() + 2);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -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

View File

@@ -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,19 @@ 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; }
constexpr bool test() {
A a;
return true;
}
int main(int, char**) {
A a;
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -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 (!TEST_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;
}

View File

@@ -18,11 +18,12 @@ 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>
@@ -36,7 +37,7 @@ template <class T, bool ConvertibleToT = false>
struct Transparent {
T t;
explicit operator T() const
TEST_CONSTEXPR explicit operator T() const
requires ConvertibleToT
{
return t;
@@ -57,10 +58,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;
}
@@ -68,7 +69,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;
}
@@ -76,7 +77,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;
}
};
@@ -101,13 +102,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_;
@@ -117,11 +118,13 @@ public:
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

View File

@@ -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

View File

@@ -13,6 +13,7 @@
#include <vector>
#include "test_iterators.h"
#include "test_macros.h"
template <class T,
class Iterator = three_way_random_access_iterator<T*>,
@@ -26,54 +27,60 @@ 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) {}
explicit TEST_CONSTEXPR_CXX20 MinSequenceContainer(It first, It last) : data_(first, last) {}
TEST_CONSTEXPR_CXX20 MinSequenceContainer(std::initializer_list<T> il) : data_(il) {}
template <class It>
void assign(It first, It last) {
TEST_CONSTEXPR_CXX20 void assign(It first, It last) {
data_.assign(first, last);
}
void assign(std::initializer_list<T> il) { data_.assign(il); }
void assign(size_type n, value_type t) { data_.assign(n, t); }
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(); }
TEST_CONSTEXPR_CXX20 void assign(std::initializer_list<T> il) { data_.assign(il); }
TEST_CONSTEXPR_CXX20 void assign(size_type n, value_type t) { data_.assign(n, t); }
TEST_CONSTEXPR_CXX20 iterator begin() { return iterator(data_.data()); }
TEST_CONSTEXPR_CXX20 const_iterator begin() const { return const_iterator(data_.data()); }
TEST_CONSTEXPR_CXX20 const_iterator cbegin() const { return const_iterator(data_.data()); }
TEST_CONSTEXPR_CXX20 iterator end() { return begin() + size(); }
TEST_CONSTEXPR_CXX20 const_iterator end() const { return begin() + size(); }
TEST_CONSTEXPR_CXX20 size_type size() const { return static_cast<size_type>(data_.size()); }
TEST_CONSTEXPR_CXX20 bool empty() const { return data_.empty(); }
void clear() { data_.clear(); }
TEST_CONSTEXPR_CXX20 void clear() { data_.clear(); }
template <class It>
iterator insert(const_iterator p, It first, It last) {
TEST_CONSTEXPR_CXX20 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_CXX20 iterator insert(const_iterator p, T value) {
return from_vector_iterator(data_.insert(to_vector_iterator(p), std::move(value)));
}
template <class Range>
iterator insert_range(const_iterator p, Range&& rg) {
TEST_CONSTEXPR_CXX20 iterator insert_range(const_iterator p, Range&& rg) {
return from_vector_iterator(data_.insert_range(to_vector_iterator(p), std::forward<Range>(rg)));
}
iterator erase(const_iterator first, const_iterator last) {
TEST_CONSTEXPR_CXX20 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_CXX20 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_CXX20 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_CXX20 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_CXX20 iterator from_vector_iterator(std::vector<T>::iterator it) {
return it - data_.begin() + begin();
}
std::vector<T> data_;
};