mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-16 01:16:36 +00:00
[libc++] implement std::flat_multimap
(#113835)
fixes https://github.com/llvm/llvm-project/issues/105190 --------- Co-authored-by: Hui Xie <huixie@Mac.broadband> Co-authored-by: Hui Xie <huixie@Huis-MacBook-Pro.local>
This commit is contained in:
parent
aba0476f23
commit
def50f701f
@ -330,6 +330,10 @@ Status
|
||||
---------------------------------------------------------- -----------------
|
||||
``__cpp_lib_expected`` ``202211L``
|
||||
---------------------------------------------------------- -----------------
|
||||
``__cpp_lib_flat_map`` ``202207L``
|
||||
---------------------------------------------------------- -----------------
|
||||
``__cpp_lib_flat_set`` *unimplemented*
|
||||
---------------------------------------------------------- -----------------
|
||||
``__cpp_lib_format_ranges`` ``202207L``
|
||||
---------------------------------------------------------- -----------------
|
||||
``__cpp_lib_formatters`` *unimplemented*
|
||||
|
@ -52,7 +52,7 @@
|
||||
"`P2443R1 <https://wg21.link/P2443R1>`__","``views::chunk_by``","2022-02 (Virtual)","|Complete|","18",""
|
||||
"","","","","",""
|
||||
"`P0009R18 <https://wg21.link/P0009R18>`__","mdspan: A Non-Owning Multidimensional Array Reference","2022-07 (Virtual)","|Complete|","18",""
|
||||
"`P0429R9 <https://wg21.link/P0429R9>`__","A Standard ``flat_map``","2022-07 (Virtual)","|In Progress|","",""
|
||||
"`P0429R9 <https://wg21.link/P0429R9>`__","A Standard ``flat_map``","2022-07 (Virtual)","|Complete|","",""
|
||||
"`P1169R4 <https://wg21.link/P1169R4>`__","``static operator()``","2022-07 (Virtual)","|Complete|","16",""
|
||||
"`P1222R4 <https://wg21.link/P1222R4>`__","A Standard ``flat_set``","2022-07 (Virtual)","","",""
|
||||
"`P1223R5 <https://wg21.link/P1223R5>`__","``ranges::find_last()``, ``ranges::find_last_if()``, and ``ranges::find_last_if_not()``","2022-07 (Virtual)","|Complete|","19",""
|
||||
|
|
@ -362,8 +362,11 @@ set(files
|
||||
__filesystem/space_info.h
|
||||
__filesystem/u8path.h
|
||||
__flat_map/flat_map.h
|
||||
__flat_map/flat_multimap.h
|
||||
__flat_map/key_value_iterator.h
|
||||
__flat_map/sorted_equivalent.h
|
||||
__flat_map/sorted_unique.h
|
||||
__flat_map/utils.h
|
||||
__format/buffer.h
|
||||
__format/concepts.h
|
||||
__format/container_adaptor.h
|
||||
|
@ -29,9 +29,11 @@
|
||||
#include <__cstddef/ptrdiff_t.h>
|
||||
#include <__flat_map/key_value_iterator.h>
|
||||
#include <__flat_map/sorted_unique.h>
|
||||
#include <__flat_map/utils.h>
|
||||
#include <__functional/invoke.h>
|
||||
#include <__functional/is_transparent.h>
|
||||
#include <__functional/operations.h>
|
||||
#include <__fwd/vector.h>
|
||||
#include <__iterator/concepts.h>
|
||||
#include <__iterator/distance.h>
|
||||
#include <__iterator/iterator_traits.h>
|
||||
@ -131,7 +133,7 @@ private:
|
||||
_LIBCPP_HIDE_FROM_ABI static constexpr bool __allocator_ctor_constraint =
|
||||
_And<uses_allocator<key_container_type, _Allocator>, uses_allocator<mapped_container_type, _Allocator>>::value;
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI static constexpr bool __is_compare_transparent = __is_transparent_v<_Compare, _Compare>;
|
||||
_LIBCPP_HIDE_FROM_ABI static constexpr bool __is_compare_transparent = __is_transparent_v<_Compare>;
|
||||
|
||||
public:
|
||||
// [flat.map.cons], construct/copy/destroy
|
||||
@ -153,7 +155,7 @@ public:
|
||||
# if _LIBCPP_HAS_EXCEPTIONS
|
||||
} catch (...) {
|
||||
__other.clear();
|
||||
// gcc does not like the `throw` keyword in a conditional noexcept function
|
||||
// gcc does not like the `throw` keyword in a conditionally noexcept function
|
||||
if constexpr (!(is_nothrow_move_constructible_v<_KeyContainer> &&
|
||||
is_nothrow_move_constructible_v<_MappedContainer> && is_nothrow_move_constructible_v<_Compare>)) {
|
||||
throw;
|
||||
@ -518,16 +520,16 @@ public:
|
||||
return emplace_hint(__hint, std::move(__x));
|
||||
}
|
||||
|
||||
template <class _Pp>
|
||||
requires is_constructible_v<pair<key_type, mapped_type>, _Pp>
|
||||
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(_Pp&& __x) {
|
||||
return emplace(std::forward<_Pp>(__x));
|
||||
template <class _PairLike>
|
||||
requires is_constructible_v<pair<key_type, mapped_type>, _PairLike>
|
||||
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(_PairLike&& __x) {
|
||||
return emplace(std::forward<_PairLike>(__x));
|
||||
}
|
||||
|
||||
template <class _Pp>
|
||||
requires is_constructible_v<pair<key_type, mapped_type>, _Pp>
|
||||
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, _Pp&& __x) {
|
||||
return emplace_hint(__hint, std::forward<_Pp>(__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) {
|
||||
return emplace_hint(__hint, std::forward<_PairLike>(__x));
|
||||
}
|
||||
|
||||
template <class _InputIterator>
|
||||
@ -860,22 +862,10 @@ private:
|
||||
__containers_.values.erase(__containers_.values.begin() + __dist, __containers_.values.end());
|
||||
}
|
||||
|
||||
template <class _InputIterator, class _Sentinel>
|
||||
_LIBCPP_HIDE_FROM_ABI size_type __append(_InputIterator __first, _Sentinel __last) {
|
||||
size_type __num_of_appended = 0;
|
||||
for (; __first != __last; ++__first) {
|
||||
value_type __kv = *__first;
|
||||
__containers_.keys.insert(__containers_.keys.end(), std::move(__kv.first));
|
||||
__containers_.values.insert(__containers_.values.end(), std::move(__kv.second));
|
||||
++__num_of_appended;
|
||||
}
|
||||
return __num_of_appended;
|
||||
}
|
||||
|
||||
template <bool _WasSorted, class _InputIterator, class _Sentinel>
|
||||
_LIBCPP_HIDE_FROM_ABI void __append_sort_merge_unique(_InputIterator __first, _Sentinel __last) {
|
||||
auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
|
||||
size_t __num_of_appended = __append(std::move(__first), std::move(__last));
|
||||
size_t __num_of_appended = __flat_map_utils::__append(*this, std::move(__first), std::move(__last));
|
||||
if (__num_of_appended != 0) {
|
||||
auto __zv = ranges::views::zip(__containers_.keys, __containers_.values);
|
||||
auto __append_start_offset = __containers_.keys.size() - __num_of_appended;
|
||||
@ -963,7 +953,8 @@ private:
|
||||
|
||||
if (__key_it == __containers_.keys.end() || __compare_(__key, *__key_it)) {
|
||||
return pair<iterator, bool>(
|
||||
__try_emplace_exact_hint(
|
||||
__flat_map_utils::__emplace_exact_pos(
|
||||
*this,
|
||||
std::move(__key_it),
|
||||
std::move(__mapped_it),
|
||||
std::forward<_KeyArg>(__key),
|
||||
@ -989,10 +980,13 @@ private:
|
||||
_LIBCPP_HIDE_FROM_ABI 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 {
|
||||
__try_emplace_exact_hint(
|
||||
__hint.__key_iter_, __hint.__mapped_iter_, std::forward<_Kp>(__key), std::forward<_Args>(__args)...),
|
||||
true};
|
||||
return {__flat_map_utils::__emplace_exact_pos(
|
||||
*this,
|
||||
__hint.__key_iter_,
|
||||
__hint.__mapped_iter_,
|
||||
std::forward<_Kp>(__key),
|
||||
std::forward<_Args>(__args)...),
|
||||
true};
|
||||
} else {
|
||||
// key equals
|
||||
auto __dist = __hint - cbegin();
|
||||
@ -1003,49 +997,6 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
template <class _IterK, class _IterM, class _KeyArg, class... _MArgs>
|
||||
_LIBCPP_HIDE_FROM_ABI iterator
|
||||
__try_emplace_exact_hint(_IterK&& __it_key, _IterM&& __it_mapped, _KeyArg&& __key, _MArgs&&... __mapped_args) {
|
||||
auto __on_key_failed = std::__make_exception_guard([&]() noexcept {
|
||||
if constexpr (__container_traits<_KeyContainer>::__emplacement_has_strong_exception_safety_guarantee) {
|
||||
// Nothing to roll back!
|
||||
} else {
|
||||
// we need to clear both because we don't know the state of our keys anymore
|
||||
clear() /* noexcept */;
|
||||
}
|
||||
});
|
||||
auto __key_it = __containers_.keys.emplace(__it_key, std::forward<_KeyArg>(__key));
|
||||
__on_key_failed.__complete();
|
||||
|
||||
auto __on_value_failed = std::__make_exception_guard([&]() noexcept {
|
||||
if constexpr (!__container_traits<_MappedContainer>::__emplacement_has_strong_exception_safety_guarantee) {
|
||||
// we need to clear both because we don't know the state of our values anymore
|
||||
clear() /* noexcept */;
|
||||
} else {
|
||||
// In this case, we know the values are just like before we attempted emplacement,
|
||||
// and we also know that the keys have been emplaced successfully. Just roll back the keys.
|
||||
# if _LIBCPP_HAS_EXCEPTIONS
|
||||
try {
|
||||
# endif // _LIBCPP_HAS_EXCEPTIONS
|
||||
__containers_.keys.erase(__key_it);
|
||||
# if _LIBCPP_HAS_EXCEPTIONS
|
||||
} catch (...) {
|
||||
// Now things are funky for real. We're failing to rollback the keys.
|
||||
// Just give up and clear the whole thing.
|
||||
//
|
||||
// Also, swallow the exception that happened during the rollback and let the
|
||||
// original value-emplacement exception propagate normally.
|
||||
clear() /* noexcept */;
|
||||
}
|
||||
# endif // _LIBCPP_HAS_EXCEPTIONS
|
||||
}
|
||||
});
|
||||
auto __mapped_it = __containers_.values.emplace(__it_mapped, std::forward<_MArgs>(__mapped_args)...);
|
||||
__on_value_failed.__complete();
|
||||
|
||||
return iterator(std::move(__key_it), std::move(__mapped_it));
|
||||
}
|
||||
|
||||
template <class _Kp, class _Mapped>
|
||||
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_or_assign(_Kp&& __key, _Mapped&& __mapped) {
|
||||
auto __r = try_emplace(std::forward<_Kp>(__key), std::forward<_Mapped>(__mapped));
|
||||
@ -1087,8 +1038,10 @@ private:
|
||||
friend typename flat_map<_Key2, _Tp2, _Compare2, _KeyContainer2, _MappedContainer2>::size_type
|
||||
erase_if(flat_map<_Key2, _Tp2, _Compare2, _KeyContainer2, _MappedContainer2>&, _Predicate);
|
||||
|
||||
friend __flat_map_utils;
|
||||
|
||||
containers __containers_;
|
||||
[[no_unique_address]] key_compare __compare_;
|
||||
_LIBCPP_NO_UNIQUE_ADDRESS key_compare __compare_;
|
||||
|
||||
struct __key_equiv {
|
||||
_LIBCPP_HIDE_FROM_ABI __key_equiv(key_compare __c) : __comp_(__c) {}
|
||||
@ -1187,22 +1140,20 @@ template <ranges::input_range _Range,
|
||||
class _Compare = less<__range_key_type<_Range>>,
|
||||
class _Allocator = allocator<byte>,
|
||||
class = __enable_if_t<!__is_allocator<_Compare>::value && __is_allocator<_Allocator>::value>>
|
||||
flat_map(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator())
|
||||
-> flat_map<
|
||||
__range_key_type<_Range>,
|
||||
__range_mapped_type<_Range>,
|
||||
_Compare,
|
||||
vector<__range_key_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_key_type<_Range>>>,
|
||||
vector<__range_mapped_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_mapped_type<_Range>>>>;
|
||||
flat_map(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator()) -> flat_map<
|
||||
__range_key_type<_Range>,
|
||||
__range_mapped_type<_Range>,
|
||||
_Compare,
|
||||
vector<__range_key_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_key_type<_Range>>>,
|
||||
vector<__range_mapped_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_mapped_type<_Range>>>>;
|
||||
|
||||
template <ranges::input_range _Range, class _Allocator, class = __enable_if_t<__is_allocator<_Allocator>::value>>
|
||||
flat_map(from_range_t, _Range&&, _Allocator)
|
||||
-> flat_map<
|
||||
__range_key_type<_Range>,
|
||||
__range_mapped_type<_Range>,
|
||||
less<__range_key_type<_Range>>,
|
||||
vector<__range_key_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_key_type<_Range>>>,
|
||||
vector<__range_mapped_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_mapped_type<_Range>>>>;
|
||||
flat_map(from_range_t, _Range&&, _Allocator) -> flat_map<
|
||||
__range_key_type<_Range>,
|
||||
__range_mapped_type<_Range>,
|
||||
less<__range_key_type<_Range>>,
|
||||
vector<__range_key_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_key_type<_Range>>>,
|
||||
vector<__range_mapped_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_mapped_type<_Range>>>>;
|
||||
|
||||
template <class _Key, class _Tp, class _Compare = less<_Key>>
|
||||
requires(!__is_allocator<_Compare>::value)
|
||||
|
1010
libcxx/include/__flat_map/flat_multimap.h
Normal file
1010
libcxx/include/__flat_map/flat_multimap.h
Normal file
File diff suppressed because it is too large
Load Diff
31
libcxx/include/__flat_map/sorted_equivalent.h
Normal file
31
libcxx/include/__flat_map/sorted_equivalent.h
Normal file
@ -0,0 +1,31 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#ifndef _LIBCPP___FLAT_MAP_SORTED_EQUIVALENT_H
|
||||
#define _LIBCPP___FLAT_MAP_SORTED_EQUIVALENT_H
|
||||
|
||||
#include <__config>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER >= 23
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
struct sorted_equivalent_t {
|
||||
explicit sorted_equivalent_t() = default;
|
||||
};
|
||||
inline constexpr sorted_equivalent_t sorted_equivalent{};
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 23
|
||||
|
||||
#endif // _LIBCPP___FLAT_MAP_SORTED_EQUIVALENT_H
|
103
libcxx/include/__flat_map/utils.h
Normal file
103
libcxx/include/__flat_map/utils.h
Normal file
@ -0,0 +1,103 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _LIBCPP___FLAT_MAP_UTILS_H
|
||||
#define _LIBCPP___FLAT_MAP_UTILS_H
|
||||
|
||||
#include <__config>
|
||||
#include <__type_traits/container_traits.h>
|
||||
#include <__utility/exception_guard.h>
|
||||
#include <__utility/forward.h>
|
||||
#include <__utility/move.h>
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
#if _LIBCPP_STD_VER >= 23
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
// These utilities are defined in a class instead of a namespace so that this class can be befriended more easily.
|
||||
struct __flat_map_utils {
|
||||
// Emplace a {key: value} into a flat_{multi}map, at the exact position that
|
||||
// __it_key and __it_mapped point to, assuming that the key is not already present in the map.
|
||||
// When an exception is thrown during the emplacement, the function will try its best to
|
||||
// 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(
|
||||
_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;
|
||||
if constexpr (__container_traits<_KeyContainer>::__emplacement_has_strong_exception_safety_guarantee) {
|
||||
// Nothing to roll back!
|
||||
} else {
|
||||
// we need to clear both because we don't know the state of our keys anymore
|
||||
__map.clear() /* noexcept */;
|
||||
}
|
||||
});
|
||||
auto __key_it = __map.__containers_.keys.emplace(__it_key, std::forward<_KeyArg>(__key));
|
||||
__on_key_failed.__complete();
|
||||
|
||||
auto __on_value_failed = std::__make_exception_guard([&]() noexcept {
|
||||
using _MappedContainer = typename _Map::mapped_container_type;
|
||||
if constexpr (!__container_traits<_MappedContainer>::__emplacement_has_strong_exception_safety_guarantee) {
|
||||
// we need to clear both because we don't know the state of our values anymore
|
||||
__map.clear() /* noexcept */;
|
||||
} else {
|
||||
// In this case, we know the values are just like before we attempted emplacement,
|
||||
// and we also know that the keys have been emplaced successfully. Just roll back the keys.
|
||||
# if _LIBCPP_HAS_EXCEPTIONS
|
||||
try {
|
||||
# endif // _LIBCPP_HAS_EXCEPTIONS
|
||||
__map.__containers_.keys.erase(__key_it);
|
||||
# if _LIBCPP_HAS_EXCEPTIONS
|
||||
} catch (...) {
|
||||
// Now things are funky for real. We're failing to rollback the keys.
|
||||
// Just give up and clear the whole thing.
|
||||
//
|
||||
// Also, swallow the exception that happened during the rollback and let the
|
||||
// original value-emplacement exception propagate normally.
|
||||
__map.clear() /* noexcept */;
|
||||
}
|
||||
# endif // _LIBCPP_HAS_EXCEPTIONS
|
||||
}
|
||||
});
|
||||
auto __mapped_it = __map.__containers_.values.emplace(__it_mapped, std::forward<_MArgs>(__mapped_args)...);
|
||||
__on_value_failed.__complete();
|
||||
|
||||
return typename _Map::iterator(std::move(__key_it), std::move(__mapped_it));
|
||||
}
|
||||
|
||||
// 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
|
||||
__append(_Map& __map, _InputIterator __first, _Sentinel __last) {
|
||||
typename _Map::size_type __num_appended = 0;
|
||||
for (; __first != __last; ++__first) {
|
||||
typename _Map::value_type __kv = *__first;
|
||||
__map.__containers_.keys.insert(__map.__containers_.keys.end(), std::move(__kv.first));
|
||||
__map.__containers_.values.insert(__map.__containers_.values.end(), std::move(__kv.second));
|
||||
++__num_appended;
|
||||
}
|
||||
return __num_appended;
|
||||
}
|
||||
};
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 23
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // #define _LIBCPP___FLAT_MAP_UTILS_H
|
@ -21,11 +21,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
#if _LIBCPP_STD_VER >= 14
|
||||
|
||||
template <class _Tp, class, class = void>
|
||||
template <class _Tp, class _Key = void, class = void>
|
||||
inline const bool __is_transparent_v = false;
|
||||
|
||||
template <class _Tp, class _Up>
|
||||
inline const bool __is_transparent_v<_Tp, _Up, __void_t<typename _Tp::is_transparent> > = true;
|
||||
template <class _Tp, class _Key>
|
||||
inline const bool __is_transparent_v<_Tp, _Key, __void_t<typename _Tp::is_transparent> > = true;
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -35,6 +35,25 @@ namespace std {
|
||||
class Predicate>
|
||||
typename flat_map<Key, T, Compare, KeyContainer, MappedContainer>::size_type
|
||||
erase_if(flat_map<Key, T, Compare, KeyContainer, MappedContainer>& c, Predicate pred);
|
||||
|
||||
// [flat.multimap], class template flat_multimap
|
||||
template<class Key, class T, class Compare = less<Key>,
|
||||
class KeyContainer = vector<Key>, class MappedContainer = vector<T>>
|
||||
class flat_multimap;
|
||||
|
||||
struct sorted_equivalent_t { explicit sorted_equivalent_t() = default; };
|
||||
inline constexpr sorted_equivalent_t sorted_equivalent{};
|
||||
|
||||
template<class Key, class T, class Compare, class KeyContainer, class MappedContainer,
|
||||
class Allocator>
|
||||
struct uses_allocator<flat_multimap<Key, T, Compare, KeyContainer, MappedContainer>,
|
||||
Allocator>;
|
||||
|
||||
// [flat.multimap.erasure], erasure for flat_multimap
|
||||
template<class Key, class T, class Compare, class KeyContainer, class MappedContainer,
|
||||
class Predicate>
|
||||
typename flat_multimap<Key, T, Compare, KeyContainer, MappedContainer>::size_type
|
||||
erase_if(flat_multimap<Key, T, Compare, KeyContainer, MappedContainer>& c, Predicate pred);
|
||||
*/
|
||||
|
||||
#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
|
||||
@ -44,6 +63,8 @@ namespace std {
|
||||
|
||||
# if _LIBCPP_STD_VER >= 23
|
||||
# include <__flat_map/flat_map.h>
|
||||
# include <__flat_map/flat_multimap.h>
|
||||
# include <__flat_map/sorted_equivalent.h>
|
||||
# include <__flat_map/sorted_unique.h>
|
||||
# endif
|
||||
|
||||
|
@ -1244,9 +1244,20 @@ module std [system] {
|
||||
}
|
||||
|
||||
module flat_map {
|
||||
module flat_map { header "__flat_map/flat_map.h" }
|
||||
module flat_map {
|
||||
header "__flat_map/flat_map.h"
|
||||
export std.vector.vector
|
||||
export std.vector.fwd
|
||||
}
|
||||
module flat_multimap {
|
||||
header "__flat_map/flat_multimap.h"
|
||||
export std.vector.vector
|
||||
export std.vector.fwd
|
||||
}
|
||||
module key_value_iterator { header "__flat_map/key_value_iterator.h" }
|
||||
module sorted_equivalent { header "__flat_map/sorted_equivalent.h" }
|
||||
module sorted_unique { header "__flat_map/sorted_unique.h" }
|
||||
module utils { header "__flat_map/utils.h" }
|
||||
|
||||
header "flat_map"
|
||||
export *
|
||||
|
@ -101,6 +101,8 @@ __cpp_lib_execution 201902L <execution>
|
||||
201603L // C++17
|
||||
__cpp_lib_expected 202211L <expected>
|
||||
__cpp_lib_filesystem 201703L <filesystem>
|
||||
__cpp_lib_flat_map 202207L <flat_map>
|
||||
__cpp_lib_flat_set 202207L <flat_set>
|
||||
__cpp_lib_format 202110L <format>
|
||||
__cpp_lib_format_path 202403L <filesystem>
|
||||
__cpp_lib_format_ranges 202207L <format>
|
||||
@ -480,6 +482,8 @@ __cpp_lib_void_t 201411L <type_traits>
|
||||
# define __cpp_lib_constexpr_typeinfo 202106L
|
||||
# define __cpp_lib_containers_ranges 202202L
|
||||
# define __cpp_lib_expected 202211L
|
||||
# define __cpp_lib_flat_map 202207L
|
||||
// # define __cpp_lib_flat_set 202207L
|
||||
# define __cpp_lib_format_ranges 202207L
|
||||
// # define __cpp_lib_formatters 202302L
|
||||
# define __cpp_lib_forward_like 202207L
|
||||
|
@ -20,8 +20,6 @@ export namespace std {
|
||||
// [flat.map.erasure], erasure for flat_map
|
||||
using std::erase_if;
|
||||
|
||||
#endif // _LIBCPP_STD_VER >= 23
|
||||
#if 0
|
||||
// [flat.multimap], class template flat_multimap
|
||||
using std::flat_multimap;
|
||||
|
||||
@ -29,5 +27,5 @@ export namespace std {
|
||||
using std::sorted_equivalent_t;
|
||||
|
||||
// [flat.multimap.erasure], erasure for flat_multimap
|
||||
#endif
|
||||
#endif // _LIBCPP_STD_VER >= 23
|
||||
} // namespace std
|
||||
|
@ -0,0 +1,66 @@
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// REQUIRES: has-unix-headers
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
// UNSUPPORTED: libcpp-hardening-mode=none
|
||||
// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap(key_container_type , mapped_container_type , const key_compare& __comp = key_compare())
|
||||
// flat_multimap(const key_container_type& , const mapped_container_type& , const _Allocator& )
|
||||
// flat_multimap(const key_container_type& , const mapped_container_type& , const key_compare&, const _Allocator& )
|
||||
// void replace(key_container_type&& , mapped_container_type&&)
|
||||
//
|
||||
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "check_assertion.h"
|
||||
|
||||
int main(int, char**) {
|
||||
using M = std::flat_multimap<int, int>;
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] { M m({1, 2, 3}, {4}); }()), "flat_multimap keys and mapped containers have different size");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(([] { M m({1, 2, 3}, {4}, std::less<int>{}); }()),
|
||||
"flat_multimap keys and mapped containers have different size");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
const std::vector keys{1, 2, 3};
|
||||
const std::vector values{4};
|
||||
const std::allocator<int> alloc{};
|
||||
M m(keys, values, alloc);
|
||||
}()),
|
||||
"flat_multimap keys and mapped containers have different size");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
const std::vector keys{1, 2, 3};
|
||||
const std::vector values{4};
|
||||
const std::less<int> key_compare{};
|
||||
const std::allocator<int> alloc{};
|
||||
M m(keys, values, key_compare, alloc);
|
||||
}()),
|
||||
"flat_multimap keys and mapped containers have different size");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
std::vector keys{1, 2, 3};
|
||||
std::vector values{4};
|
||||
M m;
|
||||
m.replace(std::move(keys), std::move(values));
|
||||
}()),
|
||||
"flat_multimap keys and mapped containers have different size");
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,225 @@
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// REQUIRES: has-unix-headers
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
// UNSUPPORTED: libcpp-hardening-mode=none
|
||||
// REQUIRES: libcpp-hardening-mode=debug
|
||||
// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap(key_container_type , mapped_container_type , const key_compare& __comp = key_compare())
|
||||
// flat_multimap(const key_container_type& , const mapped_container_type& , const _Allocator& )
|
||||
// flat_multimap(const key_container_type& , const mapped_container_type& , const key_compare&, const _Allocator& )
|
||||
// void replace(key_container_type&& , mapped_container_type&&)
|
||||
//
|
||||
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "check_assertion.h"
|
||||
|
||||
int main(int, char**) {
|
||||
using M = std::flat_multimap<int, int>;
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] { M m(std::sorted_equivalent, {2, 2, 1}, {4, 5, 6}); }()), "Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] { M m(std::sorted_equivalent, {4, 2, 3}, {4, 5, 6}); }()), "Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] { M m(std::sorted_equivalent, {2, 2, 1}, {4, 5, 6}, std::less<int>{}); }()), "Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] { M m(std::sorted_equivalent, {4, 2, 3}, {4, 5, 6}, std::less<int>{}); }()), "Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
const std::vector keys{2, 2, 1};
|
||||
const std::vector values{4, 5, 6};
|
||||
const std::allocator<int> alloc{};
|
||||
M m(std::sorted_equivalent, keys, values, alloc);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
const std::vector keys{4, 2, 3};
|
||||
const std::vector values{4, 5, 6};
|
||||
const std::allocator<int> alloc{};
|
||||
M m(std::sorted_equivalent, keys, values, alloc);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
const std::vector keys{2, 2, 1};
|
||||
const std::vector values{4, 5, 6};
|
||||
const std::allocator<int> alloc{};
|
||||
const std::less<int> comp{};
|
||||
M m(std::sorted_equivalent, keys, values, comp, alloc);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
const std::vector keys{4, 2, 3};
|
||||
const std::vector values{4, 5, 6};
|
||||
const std::allocator<int> alloc{};
|
||||
const std::less<int> comp{};
|
||||
M m(std::sorted_equivalent, keys, values, comp, alloc);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
const std::vector<std::pair<int, int>> v{{2, 4}, {2, 5}, {1, 6}};
|
||||
const std::less<int> comp{};
|
||||
M m(std::sorted_equivalent, v.begin(), v.end(), comp);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
const std::vector<std::pair<int, int>> v{{4, 4}, {2, 5}, {3, 6}};
|
||||
const std::less<int> comp{};
|
||||
M m(std::sorted_equivalent, v.begin(), v.end(), comp);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
const std::vector<std::pair<int, int>> v{{2, 4}, {2, 5}, {1, 6}};
|
||||
const std::less<int> comp{};
|
||||
const std::allocator<int> alloc{};
|
||||
M m(std::sorted_equivalent, v.begin(), v.end(), comp, alloc);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
const std::vector<std::pair<int, int>> v{{4, 4}, {2, 5}, {3, 6}};
|
||||
const std::less<int> comp{};
|
||||
const std::allocator<int> alloc{};
|
||||
M m(std::sorted_equivalent, v.begin(), v.end(), comp, alloc);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
const std::vector<std::pair<int, int>> v{{2, 4}, {2, 5}, {1, 6}};
|
||||
const std::allocator<int> alloc{};
|
||||
M m(std::sorted_equivalent, v.begin(), v.end(), alloc);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
const std::vector<std::pair<int, int>> v{{4, 4}, {2, 5}, {3, 6}};
|
||||
const std::allocator<int> alloc{};
|
||||
M m(std::sorted_equivalent, v.begin(), v.end(), alloc);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
std::initializer_list<std::pair<int, int>> v{{2, 4}, {2, 5}, {1, 6}};
|
||||
const std::less<int> comp{};
|
||||
M m(std::sorted_equivalent, v, comp);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
std::initializer_list<std::pair<int, int>> v{{4, 4}, {2, 5}, {3, 6}};
|
||||
const std::less<int> comp{};
|
||||
M m(std::sorted_equivalent, v, comp);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
std::initializer_list<std::pair<int, int>> v{{2, 4}, {2, 5}, {1, 6}};
|
||||
const std::less<int> comp{};
|
||||
const std::allocator<int> alloc{};
|
||||
M m(std::sorted_equivalent, v, comp, alloc);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
std::initializer_list<std::pair<int, int>> v{{4, 4}, {2, 5}, {3, 6}};
|
||||
const std::less<int> comp{};
|
||||
const std::allocator<int> alloc{};
|
||||
M m(std::sorted_equivalent, v, comp, alloc);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
std::initializer_list<std::pair<int, int>> v{{2, 4}, {2, 5}, {1, 6}};
|
||||
const std::allocator<int> alloc{};
|
||||
M m(std::sorted_equivalent, v, alloc);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
std::initializer_list<std::pair<int, int>> v{{4, 4}, {2, 5}, {3, 6}};
|
||||
const std::allocator<int> alloc{};
|
||||
M m(std::sorted_equivalent, v, alloc);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
const std::vector<std::pair<int, int>> v{{2, 4}, {2, 5}, {1, 6}};
|
||||
M m;
|
||||
m.insert(std::sorted_equivalent, v.begin(), v.end());
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
const std::vector<std::pair<int, int>> v{{4, 4}, {2, 5}, {3, 6}};
|
||||
M m;
|
||||
m.insert(std::sorted_equivalent, v.begin(), v.end());
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
std::initializer_list<std::pair<int, int>> v{{2, 4}, {2, 5}, {1, 6}};
|
||||
M m;
|
||||
m.insert(std::sorted_equivalent, v);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
std::initializer_list<std::pair<int, int>> v{{4, 4}, {2, 5}, {3, 6}};
|
||||
M m;
|
||||
m.insert(std::sorted_equivalent, v);
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
|
||||
TEST_LIBCPP_ASSERT_FAILURE(
|
||||
([] {
|
||||
std::vector keys{2, 1, 3};
|
||||
std::vector values{4, 5, 6};
|
||||
M m;
|
||||
m.replace(std::move(keys), std::move(values));
|
||||
}()),
|
||||
"Key container is not sorted");
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// struct sorted_equivalent_t { explicit sorted_equivalent_t() = default; };
|
||||
// inline constexpr sorted_equivalent_t sorted_equivalent{};
|
||||
|
||||
#include <cassert>
|
||||
#include <concepts>
|
||||
#include <flat_map>
|
||||
#include <type_traits>
|
||||
|
||||
template <class T>
|
||||
void implicit_test(T) {}
|
||||
|
||||
template <class T>
|
||||
concept HasImplicitDefaultCtor = requires { implicit_test<T>({}); };
|
||||
|
||||
static_assert(std::is_default_constructible_v<std::sorted_equivalent_t>);
|
||||
static_assert(std::is_trivially_default_constructible_v<std::sorted_equivalent_t>);
|
||||
static_assert(!HasImplicitDefaultCtor<std::sorted_equivalent_t>);
|
||||
|
||||
constexpr bool test() {
|
||||
{
|
||||
[[maybe_unused]] std::sorted_equivalent_t s;
|
||||
}
|
||||
{
|
||||
[[maybe_unused]] std::same_as<const std::sorted_equivalent_t&> decltype(auto) s = (std::sorted_equivalent);
|
||||
}
|
||||
{
|
||||
[[maybe_unused]] std::same_as<const std::sorted_equivalent_t> decltype(auto) copy = std::sorted_equivalent;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test();
|
||||
static_assert(test());
|
||||
|
||||
return 0;
|
||||
}
|
@ -25,7 +25,9 @@
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using M = std::flat_map<int, double, std::less<int>, KeyContainer, ValueContainer>;
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<int>, KeyContainer, ValueContainer>;
|
||||
M m;
|
||||
ASSERT_SAME_TYPE(decltype(m.empty()), bool);
|
||||
ASSERT_NOEXCEPT(m.empty());
|
||||
|
@ -14,11 +14,7 @@
|
||||
|
||||
#include <flat_map>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
int main(int, char**) {
|
||||
void f() {
|
||||
std::flat_map<int, int> c;
|
||||
c.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// Test CTAD on cases where deduction should fail.
|
||||
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
struct NotAnAllocator {
|
||||
friend bool operator<(NotAnAllocator, NotAnAllocator) { return false; }
|
||||
};
|
||||
|
||||
using P = std::pair<int, long>;
|
||||
using PC = std::pair<const int, long>;
|
||||
|
||||
template <class... Args>
|
||||
concept CanDeductFlatMap = requires { std::flat_map{std::declval<Args>()...}; };
|
||||
|
||||
static_assert(CanDeductFlatMap<std::vector<int>, std::vector<int>>);
|
||||
|
||||
// cannot deduce Key and T from nothing
|
||||
static_assert(!CanDeductFlatMap<>);
|
||||
|
||||
// cannot deduce Key and T from just (KeyContainer), even if it's a container of pairs
|
||||
static_assert(!CanDeductFlatMap<std::vector<std::pair<int, int>>>);
|
||||
|
||||
// cannot deduce Key and T from just (KeyContainer, Allocator)
|
||||
static_assert(!CanDeductFlatMap<std::vector<int>, std::allocator<std::pair<const int, int>>>);
|
||||
|
||||
// cannot deduce Key and T from just (Compare)
|
||||
static_assert(!CanDeductFlatMap<std::less<int>>);
|
||||
|
||||
// cannot deduce Key and T from just (Compare, Allocator)
|
||||
static_assert(!CanDeductFlatMap<std::less<int>, std::allocator<PC>>);
|
||||
|
||||
// cannot deduce Key and T from just (Allocator)
|
||||
static_assert(!CanDeductFlatMap<std::allocator<PC>>);
|
||||
|
||||
// cannot convert from some arbitrary unrelated type
|
||||
static_assert(!CanDeductFlatMap<NotAnAllocator>);
|
@ -169,6 +169,24 @@ void test_iter_iter() {
|
||||
std::flat_map m(mo.cbegin(), mo.cend());
|
||||
ASSERT_SAME_TYPE(decltype(m), decltype(mo));
|
||||
}
|
||||
{
|
||||
std::pair<int, int> source[3] = {{1, 1}, {2, 2}, {3, 3}};
|
||||
std::flat_map s = {source, source + 3}; // flat_map(InputIterator, InputIterator)
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_map<int, int>);
|
||||
assert(s.size() == 3);
|
||||
}
|
||||
{
|
||||
std::pair<int, int> source[3] = {{1, 1}, {2, 2}, {3, 3}};
|
||||
std::flat_map s{source, source + 3}; // flat_map(InputIterator, InputIterator)
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_map<int, int>);
|
||||
assert(s.size() == 3);
|
||||
}
|
||||
{
|
||||
std::pair<int, int> source[3] = {{1, 1}, {2, 2}, {3, 3}};
|
||||
std::flat_map s{std::sorted_unique, source, source + 3}; // flat_map(sorted_unique_t, InputIterator, InputIterator)
|
||||
static_assert(std::is_same_v<decltype(s), std::flat_map<int, int>>);
|
||||
assert(s.size() == 3);
|
||||
}
|
||||
}
|
||||
|
||||
void test_iter_iter_compare() {
|
||||
@ -227,6 +245,19 @@ void test_initializer_list() {
|
||||
ASSERT_SAME_TYPE(decltype(m), std::flat_map<int, long>);
|
||||
assert(std::ranges::equal(m, sorted_arr));
|
||||
}
|
||||
{
|
||||
std::flat_map s = {std::make_pair(1, 'a')}; // flat_map(initializer_list<pair<int, char>>)
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_map<int, char>);
|
||||
assert(s.size() == 1);
|
||||
}
|
||||
{
|
||||
using M = std::flat_map<int, short>;
|
||||
M m;
|
||||
std::flat_map s = {std::make_pair(m, m)}; // flat_map(initializer_list<pair<M, M>>)
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_map<M, M>);
|
||||
assert(s.size() == 1);
|
||||
assert(s[m] == m);
|
||||
}
|
||||
}
|
||||
|
||||
void test_initializer_list_compare() {
|
||||
@ -305,38 +336,6 @@ int main(int, char**) {
|
||||
test_from_range_compare();
|
||||
|
||||
AssociativeContainerDeductionGuidesSfinaeAway<std::flat_map, std::flat_map<int, short>>();
|
||||
{
|
||||
std::flat_map s = {std::make_pair(1, 'a')}; // flat_map(initializer_list<pair<int, char>>)
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_map<int, char>);
|
||||
assert(s.size() == 1);
|
||||
}
|
||||
{
|
||||
using M = std::flat_map<int, short>;
|
||||
M m;
|
||||
std::flat_map s = {std::make_pair(m, m)}; // flat_map(initializer_list<pair<M, M>>)
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_map<M, M>);
|
||||
assert(s.size() == 1);
|
||||
assert(s[m] == m);
|
||||
}
|
||||
|
||||
{
|
||||
std::pair<int, int> source[3] = {{1, 1}, {2, 2}, {3, 3}};
|
||||
std::flat_map s = {source, source + 3}; // flat_map(InputIterator, InputIterator)
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_map<int, int>);
|
||||
assert(s.size() == 3);
|
||||
}
|
||||
{
|
||||
std::pair<int, int> source[3] = {{1, 1}, {2, 2}, {3, 3}};
|
||||
std::flat_map s{source, source + 3}; // flat_map(InputIterator, InputIterator)
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_map<int, int>);
|
||||
assert(s.size() == 3);
|
||||
}
|
||||
{
|
||||
std::pair<int, int> source[3] = {{1, 1}, {2, 2}, {3, 3}};
|
||||
std::flat_map s{std::sorted_unique, source, source + 3}; // flat_map(sorted_unique_t, InputIterator, InputIterator)
|
||||
static_assert(std::is_same_v<decltype(s), std::flat_map<int, int>>);
|
||||
assert(s.size() == 3);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -14,56 +14,12 @@
|
||||
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
struct NotAnAllocator {
|
||||
friend bool operator<(NotAnAllocator, NotAnAllocator) { return false; }
|
||||
};
|
||||
|
||||
using P = std::pair<int, long>;
|
||||
using PC = std::pair<const int, long>;
|
||||
|
||||
void test() {
|
||||
{
|
||||
// cannot deduce Key and T from just (KeyContainer), even if it's a container of pairs
|
||||
std::vector<std::pair<int, int>> v;
|
||||
std::flat_map s(v);
|
||||
// expected-error-re@-1{{{{no viable constructor or deduction guide for deduction of template arguments of '.*flat_map'}}}}
|
||||
}
|
||||
{
|
||||
// cannot deduce Key and T from just (KeyContainer, Allocator)
|
||||
std::vector<int> v;
|
||||
std::flat_map s(v, std::allocator<std::pair<const int, int>>());
|
||||
// expected-error-re@-1{{{{no viable constructor or deduction guide for deduction of template arguments of '.*flat_map'}}}}
|
||||
}
|
||||
{
|
||||
// cannot deduce Key and T from nothing
|
||||
std::flat_map m;
|
||||
// expected-error-re@-1{{{{no viable constructor or deduction guide for deduction of template arguments of '.*flat_map'}}}}
|
||||
}
|
||||
{
|
||||
// cannot deduce Key and T from just (Compare)
|
||||
std::flat_map m(std::less<int>{});
|
||||
// expected-error-re@-1{{{{no viable constructor or deduction guide for deduction of template arguments of '.*flat_map'}}}}
|
||||
}
|
||||
{
|
||||
// cannot deduce Key and T from just (Compare, Allocator)
|
||||
std::flat_map m(std::less<int>{}, std::allocator<PC>{});
|
||||
// expected-error-re@-1{{{{no viable constructor or deduction guide for deduction of template arguments of '.*flat_map'}}}}
|
||||
}
|
||||
{
|
||||
// cannot deduce Key and T from just (Allocator)
|
||||
std::flat_map m(std::allocator<PC>{});
|
||||
// expected-error-re@-1{{{{no viable constructor or deduction guide for deduction of template arguments of '.*flat_map'}}}}
|
||||
}
|
||||
{
|
||||
// cannot convert from some arbitrary unrelated type
|
||||
NotAnAllocator a;
|
||||
std::flat_map m(a);
|
||||
// expected-error-re@-1{{{{no viable constructor or deduction guide for deduction of template arguments of '.*flat_map'}}}}
|
||||
}
|
||||
{
|
||||
// cannot deduce that the inner braced things should be std::pair and not something else
|
||||
std::flat_map m{{1, 1L}, {2, 2L}, {3, 3L}};
|
||||
|
@ -37,10 +37,12 @@ int main(int, char**) {
|
||||
{
|
||||
using C = std::flat_map<MoveOnly, MoveOnly>;
|
||||
static_assert(std::is_nothrow_default_constructible_v<C>);
|
||||
C c;
|
||||
}
|
||||
{
|
||||
using C = std::flat_map<MoveOnly, MoveOnly, std::less<MoveOnly>, std::vector<MoveOnly, test_allocator<MoveOnly>>>;
|
||||
static_assert(std::is_nothrow_default_constructible_v<C>);
|
||||
C c;
|
||||
}
|
||||
#endif // _LIBCPP_VERSION
|
||||
{
|
||||
|
@ -24,28 +24,32 @@
|
||||
|
||||
struct ThrowingDtorComp {
|
||||
bool operator()(const auto&, const auto&) const;
|
||||
~ThrowingDtorComp() noexcept(false);
|
||||
~ThrowingDtorComp() noexcept(false) {}
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
using C = std::flat_map<MoveOnly, 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>;
|
||||
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>;
|
||||
static_assert(std::is_nothrow_destructible_v<C>);
|
||||
C c;
|
||||
}
|
||||
#if defined(_LIBCPP_VERSION)
|
||||
{
|
||||
using C = std::flat_map<MoveOnly, MoveOnly, ThrowingDtorComp>;
|
||||
static_assert(!std::is_nothrow_destructible_v<C>);
|
||||
C c;
|
||||
}
|
||||
#endif // _LIBCPP_VERSION
|
||||
|
||||
|
@ -0,0 +1,51 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// [[nodiscard]] bool empty() const noexcept;
|
||||
|
||||
#include <flat_map>
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
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>;
|
||||
M m;
|
||||
ASSERT_SAME_TYPE(decltype(m.empty()), bool);
|
||||
ASSERT_NOEXCEPT(m.empty());
|
||||
assert(m.empty());
|
||||
assert(std::as_const(m).empty());
|
||||
m = {{1, 1.0}, {1, 2.0}};
|
||||
assert(!m.empty());
|
||||
m.clear();
|
||||
assert(m.empty());
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
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>>>();
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// [[nodiscard]] bool empty() const noexcept;
|
||||
|
||||
#include <flat_map>
|
||||
|
||||
void f() {
|
||||
std::flat_multimap<int, int> c;
|
||||
c.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// size_type max_size() const noexcept;
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_allocator.h"
|
||||
#include "test_macros.h"
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
using A1 = limited_allocator<int, 10>;
|
||||
using A2 = limited_allocator<int, 20>;
|
||||
using C = std::flat_multimap<int, int, std::less<int>, std::vector<int, A1>, std::vector<int, A2>>;
|
||||
ASSERT_SAME_TYPE(C::difference_type, std::ptrdiff_t);
|
||||
ASSERT_SAME_TYPE(C::size_type, std::size_t);
|
||||
const C c;
|
||||
ASSERT_NOEXCEPT(c.max_size());
|
||||
ASSERT_SAME_TYPE(decltype(c.max_size()), C::size_type);
|
||||
assert(c.max_size() <= 10);
|
||||
LIBCPP_ASSERT(c.max_size() == 10);
|
||||
}
|
||||
{
|
||||
using A1 = limited_allocator<int, 10>;
|
||||
using A2 = limited_allocator<int, 20>;
|
||||
using C = std::flat_multimap<int, int, std::less<int>, std::vector<int, A2>, std::vector<int, A1>>;
|
||||
ASSERT_SAME_TYPE(C::difference_type, std::ptrdiff_t);
|
||||
ASSERT_SAME_TYPE(C::size_type, std::size_t);
|
||||
const C c;
|
||||
ASSERT_NOEXCEPT(c.max_size());
|
||||
ASSERT_SAME_TYPE(decltype(c.max_size()), C::size_type);
|
||||
assert(c.max_size() <= 10);
|
||||
LIBCPP_ASSERT(c.max_size() == 10);
|
||||
}
|
||||
{
|
||||
using A = limited_allocator<int, (size_t)-1>;
|
||||
using C = std::flat_multimap<int, int, std::less<int>, std::vector<int, A>, std::vector<int, A>>;
|
||||
ASSERT_SAME_TYPE(C::difference_type, std::ptrdiff_t);
|
||||
ASSERT_SAME_TYPE(C::size_type, std::size_t);
|
||||
const C::size_type max_dist = static_cast<C::size_type>(std::numeric_limits<C::difference_type>::max());
|
||||
const C c;
|
||||
ASSERT_NOEXCEPT(c.max_size());
|
||||
ASSERT_SAME_TYPE(decltype(c.max_size()), C::size_type);
|
||||
assert(c.max_size() <= max_dist);
|
||||
LIBCPP_ASSERT(c.max_size() == max_dist);
|
||||
}
|
||||
{
|
||||
typedef std::flat_multimap<char, char> C;
|
||||
ASSERT_SAME_TYPE(C::difference_type, std::ptrdiff_t);
|
||||
ASSERT_SAME_TYPE(C::size_type, std::size_t);
|
||||
const C::size_type max_dist = static_cast<C::size_type>(std::numeric_limits<C::difference_type>::max());
|
||||
const C c;
|
||||
ASSERT_NOEXCEPT(c.max_size());
|
||||
ASSERT_SAME_TYPE(decltype(c.max_size()), C::size_type);
|
||||
assert(c.max_size() <= max_dist);
|
||||
assert(c.max_size() <= alloc_max_size(std::allocator<char>()));
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// size_type size() const noexcept;
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using M = std::flat_multimap<int, char, std::less<int>, KeyContainer, ValueContainer>;
|
||||
{
|
||||
const M m = {{1, 'a'}, {1, 'b'}, {4, 'd'}, {5, 'e'}, {5, 'h'}};
|
||||
ASSERT_SAME_TYPE(decltype(m.size()), std::size_t);
|
||||
ASSERT_NOEXCEPT(m.size());
|
||||
assert(m.size() == 5);
|
||||
}
|
||||
{
|
||||
const M m = {{1, 'a'}};
|
||||
ASSERT_SAME_TYPE(decltype(m.size()), std::size_t);
|
||||
ASSERT_NOEXCEPT(m.size());
|
||||
assert(m.size() == 1);
|
||||
}
|
||||
{
|
||||
const M m;
|
||||
ASSERT_SAME_TYPE(decltype(m.size()), std::size_t);
|
||||
ASSERT_NOEXCEPT(m.size());
|
||||
assert(m.size() == 0);
|
||||
}
|
||||
{
|
||||
M m;
|
||||
std::size_t s = 1000;
|
||||
for (auto i = 0u; i < s; ++i) {
|
||||
m.emplace(i, 'a');
|
||||
}
|
||||
for (auto i = 0u; i < s; ++i) {
|
||||
m.emplace(i, 'b');
|
||||
}
|
||||
ASSERT_SAME_TYPE(decltype(m.size()), std::size_t);
|
||||
ASSERT_NOEXCEPT(m.size());
|
||||
assert(m.size() == 2 * s);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<int>, std::vector<char>>();
|
||||
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 0;
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// template<class Allocator>
|
||||
// explicit flat_multimap(const Allocator& a);
|
||||
|
||||
#include <cassert>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "test_allocator.h"
|
||||
#include "../../../test_compare.h"
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
// The constructors in this subclause shall not participate in overload
|
||||
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
|
||||
// and uses_allocator_v<mapped_container_type, Alloc> is true.
|
||||
|
||||
using C = test_less<int>;
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = other_allocator<int>;
|
||||
using V1 = std::vector<int, A1>;
|
||||
using V2 = std::vector<int, A2>;
|
||||
using M1 = std::flat_multimap<int, int, C, V1, V1>;
|
||||
using M2 = std::flat_multimap<int, int, C, V1, V2>;
|
||||
using M3 = std::flat_multimap<int, int, C, V2, V1>;
|
||||
static_assert(std::is_constructible_v<M1, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, const A2&>);
|
||||
}
|
||||
{
|
||||
// explicit
|
||||
using M =
|
||||
std::flat_multimap<int,
|
||||
long,
|
||||
std::less<int>,
|
||||
std::vector<int, test_allocator<int>>,
|
||||
std::vector<long, test_allocator<long>>>;
|
||||
|
||||
static_assert(std::is_constructible_v<M, test_allocator<int>>);
|
||||
static_assert(!std::is_convertible_v<test_allocator<int>, M>);
|
||||
}
|
||||
{
|
||||
using A = test_allocator<short>;
|
||||
using M =
|
||||
std::flat_multimap<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);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap& operator=(initializer_list<value_type> il);
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
#include "test_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
{
|
||||
M m = {{8, 8}, {10, 10}};
|
||||
assert(m.size() == 2);
|
||||
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}, {2, 1}, {3, 0}, {3, 1}, {3, 2}, {4, 0}, {5, 0}, {5, 1}, {6, 0}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
}
|
||||
{
|
||||
M m = {{10, 1}, {8, 1}};
|
||||
assert(m.size() == 2);
|
||||
m = {{3, 2}};
|
||||
std::pair<double, double> expected[] = {{3, 2}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<int>, std::vector<int>>();
|
||||
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<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// explicit flat_multimap(const key_compare& comp);
|
||||
// template <class Alloc>
|
||||
// flat_multimap(const key_compare& comp, const Alloc& a);
|
||||
|
||||
#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**) {
|
||||
{
|
||||
// The constructors in this subclause shall not participate in overload
|
||||
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
|
||||
// and uses_allocator_v<mapped_container_type, Alloc> is true.
|
||||
|
||||
using C = test_less<int>;
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = other_allocator<int>;
|
||||
using M1 = std::flat_multimap<int, int, C, std::vector<int, A1>, std::vector<int, A1>>;
|
||||
using M2 = std::flat_multimap<int, int, C, std::vector<int, A1>, std::vector<int, A2>>;
|
||||
using M3 = std::flat_multimap<int, int, C, std::vector<int, A2>, std::vector<int, A1>>;
|
||||
static_assert(std::is_constructible_v<M1, const C&, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, const C&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, const C&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, const C&, const A2&>);
|
||||
}
|
||||
{
|
||||
using C = test_less<int>;
|
||||
auto m = std::flat_multimap<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_multimap<int, char*, C>, C>);
|
||||
static_assert(!std::is_convertible_v<C, std::flat_multimap<int, char*, C>>);
|
||||
|
||||
static_assert(std::is_constructible_v<std::flat_multimap<int, char*>, std::less<int>>);
|
||||
static_assert(!std::is_convertible_v<std::less<int>, std::flat_multimap<int, char*>>);
|
||||
}
|
||||
{
|
||||
using C = test_less<int>;
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = test_allocator<short>;
|
||||
auto m = std::flat_multimap<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_multimap<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_multimap<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>);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,187 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap(key_container_type key_cont, mapped_container_type mapped_cont,
|
||||
// const key_compare& comp = key_compare());
|
||||
// template<class Allocator>
|
||||
// flat_multimap(const key_container_type& key_cont, const mapped_container_type& mapped_cont,
|
||||
// const Allocator& a);
|
||||
// template<class Alloc>
|
||||
// flat_multimap(const key_container_type& key_cont, const mapped_container_type& mapped_cont,
|
||||
// const key_compare& comp, const Alloc& a);
|
||||
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "min_allocator.h"
|
||||
#include "MoveOnly.h"
|
||||
#include "test_allocator.h"
|
||||
#include "test_iterators.h"
|
||||
#include "test_macros.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 {
|
||||
return MoveOnly(first) == rhs.first && MoveOnly(second) == rhs.second;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
// The constructors in this subclause shall not participate in overload
|
||||
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
|
||||
// and uses_allocator_v<mapped_container_type, Alloc> is true.
|
||||
|
||||
using C = test_less<int>;
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = other_allocator<int>;
|
||||
using V1 = std::vector<int, A1>;
|
||||
using V2 = std::vector<int, A2>;
|
||||
using M1 = std::flat_multimap<int, int, C, V1, V1>;
|
||||
using M2 = std::flat_multimap<int, int, C, V1, V2>;
|
||||
using M3 = std::flat_multimap<int, int, C, V2, V1>;
|
||||
static_assert(std::is_constructible_v<M1, const V1&, const V1&, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, const V1&, const V1&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, const V1&, const V2&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, const V2&, const V1&, const A2&>);
|
||||
|
||||
static_assert(std::is_constructible_v<M1, const V1&, const V1&, const C&, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, const V1&, const V1&, const C&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, const V1&, const V2&, const C&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, const V2&, const V1&, const C&, const A2&>);
|
||||
}
|
||||
{
|
||||
// flat_multimap(key_container_type , mapped_container_type)
|
||||
using M = std::flat_multimap<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);
|
||||
std::pair<int, char> expected[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {2, 7}, {3, 6}, {3, 8}, {3, 9}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
|
||||
// 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(std::ranges::equal(m, expected));
|
||||
}
|
||||
{
|
||||
// flat_multimap(key_container_type , mapped_container_type)
|
||||
// move-only
|
||||
P expected[] = {{3, 3}, {3, 2}, {2, 1}, {1, 4}};
|
||||
using Ks = std::deque<int, min_allocator<int>>;
|
||||
using Vs = std::vector<MoveOnly, min_allocator<MoveOnly>>;
|
||||
using M = std::flat_multimap<int, MoveOnly, std::greater<int>, Ks, Vs>;
|
||||
Ks ks = {1, 3, 3, 2};
|
||||
Vs vs;
|
||||
vs.push_back(4);
|
||||
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_multimap(key_container_type , mapped_container_type)
|
||||
// container's allocators are used
|
||||
using A = test_allocator<int>;
|
||||
using M = std::flat_multimap<int, int, std::less<int>, std::vector<int, A>, std::deque<int, A>>;
|
||||
auto ks = std::vector<int, A>({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
|
||||
std::pair<int, int> expected[] = {{1, 1}, {1, 1}, {1, 1}, {2, 2}, {2, 2}, {2, 2}, {3, 3}, {3, 3}, {3, 3}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
assert(m.keys().get_allocator() == A(5));
|
||||
assert(m.values().get_allocator() == A(6));
|
||||
}
|
||||
{
|
||||
// flat_multimap(key_container_type , mapped_container_type, key_compare)
|
||||
using C = test_less<int>;
|
||||
using M = std::flat_multimap<int, char, C>;
|
||||
std::vector<int> ks = {1, 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));
|
||||
std::pair<int, char> expected[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {2, 7}, {3, 6}, {3, 8}, {3, 9}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
assert(m.key_comp() == C(4));
|
||||
|
||||
// explicit(false)
|
||||
M m2 = {ks, vs, C(4)};
|
||||
assert(m2 == m);
|
||||
assert(m2.key_comp() == C(4));
|
||||
}
|
||||
{
|
||||
// flat_multimap(key_container_type , mapped_container_type, const Allocator&)
|
||||
using A = test_allocator<int>;
|
||||
using M = std::flat_multimap<int, int, std::less<int>, std::vector<int, A>, std::deque<int, A>>;
|
||||
auto ks = std::vector<int, A>({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
|
||||
std::pair<int, int> expected[] = {{1, 1}, {1, 1}, {1, 1}, {2, 2}, {2, 2}, {2, 2}, {3, 3}, {3, 3}, {3, 3}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
assert(m.keys().get_allocator() == A(4));
|
||||
assert(m.values().get_allocator() == A(4));
|
||||
}
|
||||
{
|
||||
// flat_multimap(key_container_type , mapped_container_type, const Allocator&)
|
||||
// explicit(false)
|
||||
using A = test_allocator<int>;
|
||||
using M = std::flat_multimap<int, int, std::less<int>, std::vector<int, A>, std::deque<int, A>>;
|
||||
auto ks = std::vector<int, A>({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
|
||||
std::pair<int, int> expected[] = {{1, 1}, {1, 1}, {1, 1}, {2, 2}, {2, 2}, {2, 2}, {3, 3}, {3, 3}, {3, 3}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
assert(m.keys().get_allocator() == A(4));
|
||||
assert(m.values().get_allocator() == A(4));
|
||||
}
|
||||
{
|
||||
// flat_multimap(key_container_type , mapped_container_type, key_compare, const Allocator&)
|
||||
using C = test_less<int>;
|
||||
using A = test_allocator<int>;
|
||||
using M = std::flat_multimap<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));
|
||||
std::pair<int, char> expected[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {2, 7}, {3, 6}, {3, 8}, {3, 9}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
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));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap(const flat_multimap& m);
|
||||
|
||||
#include <cassert>
|
||||
#include <flat_map>
|
||||
#include <vector>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "../../../test_compare.h"
|
||||
#include "test_allocator.h"
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
using C = test_less<int>;
|
||||
std::vector<int, test_allocator<int>> ks({1, 1, 3, 3, 5}, test_allocator<int>(6));
|
||||
std::vector<char, test_allocator<char>> vs({2, 2, 1, 1, 1}, test_allocator<char>(7));
|
||||
using M = std::flat_multimap<int, char, C, decltype(ks), decltype(vs)>;
|
||||
auto mo = M(ks, vs, C(5));
|
||||
auto m = mo;
|
||||
|
||||
assert(m.key_comp() == C(5));
|
||||
assert(m.keys() == ks);
|
||||
assert(m.values() == vs);
|
||||
assert(m.keys().get_allocator() == test_allocator<int>(6));
|
||||
assert(m.values().get_allocator() == test_allocator<char>(7));
|
||||
|
||||
// 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));
|
||||
}
|
||||
{
|
||||
using C = test_less<int>;
|
||||
using Ks = std::vector<int, other_allocator<int>>;
|
||||
using Vs = std::vector<char, other_allocator<char>>;
|
||||
auto ks = Ks({1, 3, 5, 5, 5, 5}, other_allocator<int>(6));
|
||||
auto vs = Vs({2, 2, 5, 5, 5, 1}, other_allocator<char>(7));
|
||||
using M = std::flat_multimap<int, char, C, Ks, Vs>;
|
||||
auto mo = M(Ks(ks, other_allocator<int>(6)), Vs(vs, other_allocator<int>(7)), C(5));
|
||||
auto m = mo;
|
||||
|
||||
assert(m.key_comp() == C(5));
|
||||
assert(m.keys() == ks);
|
||||
assert(m.values() == vs);
|
||||
assert(m.keys().get_allocator() == other_allocator<int>(-2));
|
||||
assert(m.values().get_allocator() == other_allocator<char>(-2));
|
||||
|
||||
// mo is unchanged
|
||||
assert(mo.key_comp() == C(5));
|
||||
assert(mo.keys() == ks);
|
||||
assert(mo.values() == vs);
|
||||
assert(mo.keys().get_allocator() == other_allocator<int>(6));
|
||||
assert(mo.values().get_allocator() == other_allocator<char>(7));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap(const flat_multimap&, const allocator_type&);
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "test_macros.h"
|
||||
#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_multimap<int, int, C, V1, V1>;
|
||||
using M2 = std::flat_multimap<int, int, C, V1, V2>;
|
||||
using M3 = std::flat_multimap<int, int, C, V2, V1>;
|
||||
static_assert(std::is_constructible_v<M1, const M1&, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, const M1&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, const M2&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, const M3&, const A2&>);
|
||||
}
|
||||
{
|
||||
using C = test_less<int>;
|
||||
std::vector<int, test_allocator<int>> ks({1, 3, 3, 5, 5}, test_allocator<int>(6));
|
||||
std::vector<char, test_allocator<char>> vs({2, 2, 1, 1, 1}, test_allocator<char>(7));
|
||||
using M = std::flat_multimap<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));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap& operator=(const flat_multimap& s);
|
||||
|
||||
// Validate whether the container can be copy-assigned (move-assigned, swapped)
|
||||
// with an ADL-hijacking operator&
|
||||
|
||||
#include <flat_map>
|
||||
#include <utility>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "operator_hijacker.h"
|
||||
|
||||
void test() {
|
||||
std::flat_multimap<operator_hijacker, operator_hijacker> so;
|
||||
std::flat_multimap<operator_hijacker, operator_hijacker> s;
|
||||
s = so;
|
||||
s = std::move(so);
|
||||
swap(s, so);
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap& operator=(const flat_multimap& m);
|
||||
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "../../../test_compare.h"
|
||||
#include "test_allocator.h"
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
// test_allocator is not propagated
|
||||
using C = test_less<int>;
|
||||
std::vector<int, test_allocator<int>> ks({1, 1, 3, 3, 5}, test_allocator<int>(6));
|
||||
std::vector<char, test_allocator<char>> vs({1, 2, 3, 4, 5}, test_allocator<char>(7));
|
||||
using M = std::flat_multimap<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));
|
||||
m = mo;
|
||||
|
||||
assert(m.key_comp() == C(5));
|
||||
assert(m.keys() == ks);
|
||||
assert(m.values() == vs);
|
||||
assert(m.keys().get_allocator() == test_allocator<int>(2));
|
||||
assert(m.values().get_allocator() == test_allocator<char>(2));
|
||||
|
||||
// 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));
|
||||
}
|
||||
{
|
||||
// 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>>;
|
||||
auto ks = Ks({1, 1, 3, 3, 5}, other_allocator<int>(6));
|
||||
auto vs = Vs({2, 1, 3, 2, 1}, other_allocator<char>(7));
|
||||
using M = std::flat_multimap<int, char, C, Ks, Vs>;
|
||||
auto mo = M(Ks(ks, other_allocator<int>(6)), Vs(vs, other_allocator<int>(7)), C(5));
|
||||
auto m = M({{3, 3}, {4, 4}, {5, 5}}, C(3), other_allocator<int>(2));
|
||||
m = mo;
|
||||
|
||||
assert(m.key_comp() == C(5));
|
||||
assert(m.keys() == ks);
|
||||
assert(m.values() == vs);
|
||||
assert(m.keys().get_allocator() == other_allocator<int>(6));
|
||||
assert(m.values().get_allocator() == other_allocator<char>(7));
|
||||
|
||||
// mo is unchanged
|
||||
assert(mo.key_comp() == C(5));
|
||||
assert(mo.keys() == ks);
|
||||
assert(mo.values() == vs);
|
||||
assert(mo.keys().get_allocator() == other_allocator<int>(6));
|
||||
assert(mo.values().get_allocator() == other_allocator<char>(7));
|
||||
}
|
||||
{
|
||||
// self-assignment
|
||||
using M = std::flat_multimap<int, int>;
|
||||
M m = {{1, 1}, {3, 4}};
|
||||
m = static_cast<const M&>(m);
|
||||
assert((m == M{{1, 1}, {3, 4}}));
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// Test CTAD on cases where deduction should fail.
|
||||
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
struct NotAnAllocator {
|
||||
friend bool operator<(NotAnAllocator, NotAnAllocator) { return false; }
|
||||
};
|
||||
|
||||
using P = std::pair<int, long>;
|
||||
using PC = std::pair<const int, long>;
|
||||
|
||||
template <class... Args>
|
||||
concept CanDeductFlatMultimap = requires { std::flat_multimap{std::declval<Args>()...}; };
|
||||
|
||||
static_assert(CanDeductFlatMultimap<std::vector<int>, std::vector<int>>);
|
||||
|
||||
// cannot deduce Key and T from nothing
|
||||
static_assert(!CanDeductFlatMultimap<>);
|
||||
|
||||
// cannot deduce Key and T from just (KeyContainer), even if it's a container of pairs
|
||||
static_assert(!CanDeductFlatMultimap<std::vector<std::pair<int, int>>>);
|
||||
|
||||
// cannot deduce Key and T from just (KeyContainer, Allocator)
|
||||
static_assert(!CanDeductFlatMultimap<std::vector<int>, std::allocator<std::pair<const int, int>>>);
|
||||
|
||||
// cannot deduce Key and T from just (Compare)
|
||||
static_assert(!CanDeductFlatMultimap<std::less<int>>);
|
||||
|
||||
// cannot deduce Key and T from just (Compare, Allocator)
|
||||
static_assert(!CanDeductFlatMultimap<std::less<int>, std::allocator<PC>>);
|
||||
|
||||
// cannot deduce Key and T from just (Allocator)
|
||||
static_assert(!CanDeductFlatMultimap<std::allocator<PC>>);
|
||||
|
||||
// cannot convert from some arbitrary unrelated type
|
||||
static_assert(!CanDeductFlatMultimap<NotAnAllocator>);
|
@ -0,0 +1,343 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <climits>
|
||||
#include <deque>
|
||||
#include <initializer_list>
|
||||
#include <list>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <ranges>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "deduction_guides_sfinae_checks.h"
|
||||
#include "test_allocator.h"
|
||||
|
||||
using P = std::pair<int, long>;
|
||||
using PC = std::pair<const int, long>;
|
||||
|
||||
void test_copy() {
|
||||
{
|
||||
std::flat_multimap<long, short> source = {{1, 2}, {1, 3}};
|
||||
std::flat_multimap s(source);
|
||||
ASSERT_SAME_TYPE(decltype(s), decltype(source));
|
||||
assert(s == source);
|
||||
}
|
||||
{
|
||||
std::flat_multimap<long, short, std::greater<long>> source = {{1, 2}, {1, 3}};
|
||||
std::flat_multimap s{source}; // braces instead of parens
|
||||
ASSERT_SAME_TYPE(decltype(s), decltype(source));
|
||||
assert(s == source);
|
||||
}
|
||||
{
|
||||
std::flat_multimap<long, short, std::greater<long>> source = {{1, 2}, {1, 3}};
|
||||
std::flat_multimap s(source, std::allocator<int>());
|
||||
ASSERT_SAME_TYPE(decltype(s), decltype(source));
|
||||
assert(s == source);
|
||||
}
|
||||
}
|
||||
|
||||
void test_containers() {
|
||||
std::deque<int, test_allocator<int>> ks({1, 2, 1, 2, 2, INT_MAX, 3}, test_allocator<int>(0, 42));
|
||||
std::deque<short, test_allocator<short>> vs({1, 2, 3, 4, 5, 3, 4}, test_allocator<int>(0, 43));
|
||||
std::deque<int, test_allocator<int>> sorted_ks({1, 1, 2, 2, 2, 3, INT_MAX}, test_allocator<int>(0, 42));
|
||||
std::deque<short, test_allocator<short>> sorted_vs({1, 3, 2, 4, 5, 4, 3}, test_allocator<int>(0, 43));
|
||||
const std::pair<int, short> expected[] = {{1, 1}, {1, 3}, {2, 2}, {2, 4}, {2, 5}, {3, 4}, {INT_MAX, 3}};
|
||||
{
|
||||
std::flat_multimap s(ks, vs);
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_multimap<int, short, std::less<int>, decltype(ks), decltype(vs)>);
|
||||
assert(std::ranges::equal(s, expected));
|
||||
assert(s.keys().get_allocator().get_id() == 42);
|
||||
assert(s.values().get_allocator().get_id() == 43);
|
||||
}
|
||||
{
|
||||
std::flat_multimap s(std::sorted_equivalent, sorted_ks, sorted_vs);
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_multimap<int, short, std::less<int>, decltype(ks), decltype(vs)>);
|
||||
assert(std::ranges::equal(s, expected));
|
||||
assert(s.keys().get_allocator().get_id() == 42);
|
||||
assert(s.values().get_allocator().get_id() == 43);
|
||||
}
|
||||
{
|
||||
std::flat_multimap s(ks, vs, test_allocator<long>(0, 44));
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_multimap<int, short, std::less<int>, decltype(ks), decltype(vs)>);
|
||||
assert(std::ranges::equal(s, expected));
|
||||
assert(s.keys().get_allocator().get_id() == 44);
|
||||
assert(s.values().get_allocator().get_id() == 44);
|
||||
}
|
||||
{
|
||||
std::flat_multimap s(std::sorted_equivalent, sorted_ks, sorted_vs, test_allocator<long>(0, 44));
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_multimap<int, short, std::less<int>, decltype(ks), decltype(vs)>);
|
||||
assert(std::ranges::equal(s, expected));
|
||||
assert(s.keys().get_allocator().get_id() == 44);
|
||||
assert(s.values().get_allocator().get_id() == 44);
|
||||
}
|
||||
}
|
||||
|
||||
void test_containers_compare() {
|
||||
std::deque<int, test_allocator<int>> ks({1, 2, 1, 2, 2, INT_MAX, 3}, test_allocator<int>(0, 42));
|
||||
std::deque<short, test_allocator<short>> vs({1, 2, 3, 4, 5, 3, 4}, test_allocator<int>(0, 43));
|
||||
std::deque<int, test_allocator<int>> sorted_ks({INT_MAX, 3, 2, 2, 2, 1, 1}, test_allocator<int>(0, 42));
|
||||
std::deque<short, test_allocator<short>> sorted_vs({3, 4, 2, 4, 5, 1, 3}, test_allocator<int>(0, 43));
|
||||
const std::pair<int, short> expected[] = {{INT_MAX, 3}, {3, 4}, {2, 2}, {2, 4}, {2, 5}, {1, 1}, {1, 3}};
|
||||
{
|
||||
std::flat_multimap s(ks, vs, std::greater<int>());
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_multimap<int, short, std::greater<int>, decltype(ks), decltype(vs)>);
|
||||
assert(std::ranges::equal(s, expected));
|
||||
assert(s.keys().get_allocator().get_id() == 42);
|
||||
assert(s.values().get_allocator().get_id() == 43);
|
||||
}
|
||||
{
|
||||
std::flat_multimap s(std::sorted_equivalent, sorted_ks, sorted_vs, std::greater<int>());
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_multimap<int, short, std::greater<int>, decltype(ks), decltype(vs)>);
|
||||
assert(std::ranges::equal(s, expected));
|
||||
assert(s.keys().get_allocator().get_id() == 42);
|
||||
assert(s.values().get_allocator().get_id() == 43);
|
||||
}
|
||||
{
|
||||
std::flat_multimap s(ks, vs, std::greater<int>(), test_allocator<long>(0, 44));
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_multimap<int, short, std::greater<int>, decltype(ks), decltype(vs)>);
|
||||
assert(std::ranges::equal(s, expected));
|
||||
assert(s.keys().get_allocator().get_id() == 44);
|
||||
assert(s.values().get_allocator().get_id() == 44);
|
||||
}
|
||||
{
|
||||
std::flat_multimap s(
|
||||
std::sorted_equivalent, sorted_ks, sorted_vs, std::greater<int>(), test_allocator<long>(0, 44));
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_multimap<int, short, std::greater<int>, decltype(ks), decltype(vs)>);
|
||||
assert(std::ranges::equal(s, expected));
|
||||
assert(s.keys().get_allocator().get_id() == 44);
|
||||
assert(s.values().get_allocator().get_id() == 44);
|
||||
}
|
||||
}
|
||||
|
||||
void test_iter_iter() {
|
||||
const P arr[] = {{1, 1L}, {2, 2L}, {1, 1L}, {INT_MAX, 1L}, {3, 1L}};
|
||||
const P sorted_arr[] = {{1, 1L}, {1, 1L}, {2, 2L}, {3, 1L}, {INT_MAX, 1L}};
|
||||
const PC arrc[] = {{1, 1L}, {2, 2L}, {1, 1L}, {INT_MAX, 1L}, {3, 1L}};
|
||||
const PC sorted_arrc[] = {{1, 1L}, {1, 1L}, {2, 2L}, {3, 1L}, {INT_MAX, 1L}};
|
||||
{
|
||||
std::flat_multimap m(std::begin(arr), std::end(arr));
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(m), std::flat_multimap<int, long>);
|
||||
assert(std::ranges::equal(m, sorted_arr));
|
||||
}
|
||||
{
|
||||
std::flat_multimap m(std::begin(arrc), std::end(arrc));
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(m), std::flat_multimap<int, long>);
|
||||
assert(std::ranges::equal(m, sorted_arr));
|
||||
}
|
||||
{
|
||||
std::flat_multimap m(std::sorted_equivalent, std::begin(sorted_arr), std::end(sorted_arr));
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(m), std::flat_multimap<int, long>);
|
||||
assert(std::ranges::equal(m, sorted_arr));
|
||||
}
|
||||
{
|
||||
std::flat_multimap m(std::sorted_equivalent, std::begin(sorted_arrc), std::end(sorted_arrc));
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(m), std::flat_multimap<int, long>);
|
||||
assert(std::ranges::equal(m, sorted_arr));
|
||||
}
|
||||
{
|
||||
std::flat_multimap<int, short> mo;
|
||||
std::flat_multimap m(mo.begin(), mo.end());
|
||||
ASSERT_SAME_TYPE(decltype(m), decltype(mo));
|
||||
}
|
||||
{
|
||||
std::flat_multimap<int, short> mo;
|
||||
std::flat_multimap m(mo.cbegin(), mo.cend());
|
||||
ASSERT_SAME_TYPE(decltype(m), decltype(mo));
|
||||
}
|
||||
{
|
||||
std::pair<int, int> source[3] = {{1, 1}, {1, 1}, {3, 3}};
|
||||
std::flat_multimap s = {source, source + 3}; // flat_multimap(InputIterator, InputIterator)
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_multimap<int, int>);
|
||||
assert(s.size() == 3);
|
||||
}
|
||||
{
|
||||
std::pair<int, int> source[3] = {{1, 1}, {1, 1}, {3, 3}};
|
||||
std::flat_multimap s{source, source + 3}; // flat_multimap(InputIterator, InputIterator)
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_multimap<int, int>);
|
||||
assert(s.size() == 3);
|
||||
}
|
||||
{
|
||||
std::pair<int, int> source[3] = {{1, 1}, {1, 2}, {3, 3}};
|
||||
std::flat_multimap s{
|
||||
std::sorted_equivalent, source, source + 3}; // flat_multimap(sorted_equivalent_t, InputIterator, InputIterator)
|
||||
static_assert(std::is_same_v<decltype(s), std::flat_multimap<int, int>>);
|
||||
assert(s.size() == 3);
|
||||
}
|
||||
}
|
||||
|
||||
void test_iter_iter_compare() {
|
||||
const P arr[] = {{1, 1L}, {2, 2L}, {1, 1L}, {INT_MAX, 1L}, {3, 1L}};
|
||||
const P sorted_arr[] = {{INT_MAX, 1L}, {3, 1L}, {2, 2L}, {1, 1L}, {1, 1L}};
|
||||
const PC arrc[] = {{1, 1L}, {2, 2L}, {1, 1L}, {INT_MAX, 1L}, {3, 1L}};
|
||||
const PC sorted_arrc[] = {{INT_MAX, 1L}, {3, 1L}, {2, 2L}, {1, 1L}, {1, 1L}};
|
||||
using C = std::greater<long long>;
|
||||
{
|
||||
std::flat_multimap m(std::begin(arr), std::end(arr), C());
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(m), std::flat_multimap<int, long, C>);
|
||||
assert(std::ranges::equal(m, sorted_arr));
|
||||
}
|
||||
{
|
||||
std::flat_multimap m(std::begin(arrc), std::end(arrc), C());
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(m), std::flat_multimap<int, long, C>);
|
||||
assert(std::ranges::equal(m, sorted_arr));
|
||||
}
|
||||
{
|
||||
std::flat_multimap m(std::sorted_equivalent, std::begin(sorted_arr), std::end(sorted_arr), C());
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(m), std::flat_multimap<int, long, C>);
|
||||
assert(std::ranges::equal(m, sorted_arr));
|
||||
}
|
||||
{
|
||||
std::flat_multimap m(std::sorted_equivalent, std::begin(sorted_arrc), std::end(sorted_arrc), C());
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(m), std::flat_multimap<int, long, C>);
|
||||
assert(std::ranges::equal(m, sorted_arr));
|
||||
}
|
||||
{
|
||||
std::flat_multimap<int, short> mo;
|
||||
std::flat_multimap m(mo.begin(), mo.end(), C());
|
||||
ASSERT_SAME_TYPE(decltype(m), std::flat_multimap<int, short, C>);
|
||||
}
|
||||
{
|
||||
std::flat_multimap<int, short> mo;
|
||||
std::flat_multimap m(mo.cbegin(), mo.cend(), C());
|
||||
ASSERT_SAME_TYPE(decltype(m), std::flat_multimap<int, short, C>);
|
||||
}
|
||||
}
|
||||
|
||||
void test_initializer_list() {
|
||||
const P sorted_arr[] = {{1, 1L}, {1, 1L}, {2, 2L}, {3, 1L}, {INT_MAX, 1L}};
|
||||
{
|
||||
std::flat_multimap m{std::pair{1, 1L}, {2, 2L}, {1, 1L}, {INT_MAX, 1L}, {3, 1L}};
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(m), std::flat_multimap<int, long>);
|
||||
assert(std::ranges::equal(m, sorted_arr));
|
||||
}
|
||||
{
|
||||
std::flat_multimap m(std::sorted_equivalent, {std::pair{1, 1L}, {1, 1L}, {2, 2L}, {3, 1L}, {INT_MAX, 1L}});
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(m), std::flat_multimap<int, long>);
|
||||
assert(std::ranges::equal(m, sorted_arr));
|
||||
}
|
||||
{
|
||||
std::flat_multimap s = {std::make_pair(1, 'a')}; // flat_multimap(initializer_list<pair<int, char>>)
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_multimap<int, char>);
|
||||
assert(s.size() == 1);
|
||||
}
|
||||
{
|
||||
using M = std::flat_multimap<int, short>;
|
||||
M m;
|
||||
std::flat_multimap s = {std::make_pair(m, m)}; // flat_multimap(initializer_list<pair<M, M>>)
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_multimap<M, M>);
|
||||
assert(s.size() == 1);
|
||||
assert(s.find(m)->second == m);
|
||||
}
|
||||
}
|
||||
|
||||
void test_initializer_list_compare() {
|
||||
const P sorted_arr[] = {{INT_MAX, 1L}, {3, 1L}, {2, 2L}, {1, 1L}, {1, 1L}};
|
||||
using C = std::greater<long long>;
|
||||
{
|
||||
std::flat_multimap m({std::pair{1, 1L}, {2, 2L}, {1, 1L}, {INT_MAX, 1L}, {3, 1L}}, C());
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(m), std::flat_multimap<int, long, C>);
|
||||
assert(std::ranges::equal(m, sorted_arr));
|
||||
}
|
||||
{
|
||||
std::flat_multimap m(std::sorted_equivalent, {std::pair{INT_MAX, 1L}, {3, 1L}, {2, 2L}, {1, 1L}, {1, 1L}}, C());
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(m), std::flat_multimap<int, long, C>);
|
||||
assert(std::ranges::equal(m, sorted_arr));
|
||||
}
|
||||
}
|
||||
|
||||
void test_from_range() {
|
||||
std::list<std::pair<int, short>> r = {{1, 1}, {2, 2}, {1, 1}, {INT_MAX, 4}, {3, 5}};
|
||||
const std::pair<int, short> expected[] = {{1, 1}, {1, 1}, {2, 2}, {3, 5}, {INT_MAX, 4}};
|
||||
{
|
||||
std::flat_multimap s(std::from_range, r);
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_multimap<int, short, std::less<int>>);
|
||||
assert(std::ranges::equal(s, expected));
|
||||
}
|
||||
{
|
||||
std::flat_multimap s(std::from_range, r, test_allocator<long>(0, 42));
|
||||
ASSERT_SAME_TYPE(
|
||||
decltype(s),
|
||||
std::flat_multimap<int,
|
||||
short,
|
||||
std::less<int>,
|
||||
std::vector<int, test_allocator<int>>,
|
||||
std::vector<short, test_allocator<short>>>);
|
||||
assert(std::ranges::equal(s, expected));
|
||||
assert(s.keys().get_allocator().get_id() == 42);
|
||||
assert(s.values().get_allocator().get_id() == 42);
|
||||
}
|
||||
}
|
||||
|
||||
void test_from_range_compare() {
|
||||
std::list<std::pair<int, short>> r = {{1, 1}, {2, 2}, {1, 1}, {INT_MAX, 4}, {3, 5}};
|
||||
const std::pair<int, short> expected[] = {{INT_MAX, 4}, {3, 5}, {2, 2}, {1, 1}, {1, 1}};
|
||||
{
|
||||
std::flat_multimap s(std::from_range, r, std::greater<int>());
|
||||
ASSERT_SAME_TYPE(decltype(s), std::flat_multimap<int, short, std::greater<int>>);
|
||||
assert(std::ranges::equal(s, expected));
|
||||
}
|
||||
{
|
||||
std::flat_multimap s(std::from_range, r, std::greater<int>(), test_allocator<long>(0, 42));
|
||||
ASSERT_SAME_TYPE(
|
||||
decltype(s),
|
||||
std::flat_multimap<int,
|
||||
short,
|
||||
std::greater<int>,
|
||||
std::vector<int, test_allocator<int>>,
|
||||
std::vector<short, test_allocator<short>>>);
|
||||
assert(std::ranges::equal(s, expected));
|
||||
assert(s.keys().get_allocator().get_id() == 42);
|
||||
assert(s.values().get_allocator().get_id() == 42);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
// Each test function also tests the sorted_equivalent-prefixed and allocator-suffixed overloads.
|
||||
test_copy();
|
||||
test_containers();
|
||||
test_containers_compare();
|
||||
test_iter_iter();
|
||||
test_iter_iter_compare();
|
||||
test_initializer_list();
|
||||
test_initializer_list_compare();
|
||||
test_from_range();
|
||||
test_from_range_compare();
|
||||
|
||||
AssociativeContainerDeductionGuidesSfinaeAway<std::flat_multimap, std::flat_multimap<int, short>>();
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// Test CTAD on cases where deduction should fail.
|
||||
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
struct NotAnAllocator {
|
||||
friend bool operator<(NotAnAllocator, NotAnAllocator) { return false; }
|
||||
};
|
||||
|
||||
using P = std::pair<int, long>;
|
||||
using PC = std::pair<const int, long>;
|
||||
|
||||
void test() {
|
||||
{
|
||||
// cannot deduce that the inner braced things should be std::pair and not something else
|
||||
std::flat_multimap m{{1, 1L}, {2, 2L}, {3, 3L}};
|
||||
// expected-error-re@-1{{{{no viable constructor or deduction guide for deduction of template arguments of '.*flat_multimap'}}}}
|
||||
}
|
||||
{
|
||||
// cannot deduce that the inner braced things should be std::pair and not something else
|
||||
std::flat_multimap m({{1, 1L}, {2, 2L}, {3, 3L}}, std::less<int>());
|
||||
// expected-error-re@-1{{{{no viable constructor or deduction guide for deduction of template arguments of '.*flat_multimap'}}}}
|
||||
}
|
||||
{
|
||||
// cannot deduce that the inner braced things should be std::pair and not something else
|
||||
std::flat_multimap m({{1, 1L}, {2, 2L}, {3, 3L}}, std::less<int>(), std::allocator<PC>());
|
||||
// expected-error-re@-1{{{{no viable constructor or deduction guide for deduction of template arguments of '.*flat_multimap'}}}}
|
||||
}
|
||||
{
|
||||
// cannot deduce that the inner braced things should be std::pair and not something else
|
||||
std::flat_multimap m({{1, 1L}, {2, 2L}, {3, 3L}}, std::allocator<PC>());
|
||||
// expected-error-re@-1{{{{no viable constructor or deduction guide for deduction of template arguments of '.*flat_multimap'}}}}
|
||||
}
|
||||
{
|
||||
// since we have parens, not braces, this deliberately does not find the initializer_list constructor
|
||||
std::flat_multimap m(P{1, 1L});
|
||||
// expected-error-re@-1{{{{no viable constructor or deduction guide for deduction of template arguments of '.*flat_multimap'}}}}
|
||||
}
|
||||
{
|
||||
// since we have parens, not braces, this deliberately does not find the initializer_list constructor
|
||||
std::flat_multimap m(PC{1, 1L});
|
||||
// expected-error-re@-1{{{{no viable constructor or deduction guide for deduction of template arguments of '.*flat_multimap'}}}}
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
// UNSUPPORTED: availability-pmr-missing
|
||||
|
||||
// <flat_map>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <climits>
|
||||
#include <deque>
|
||||
#include <initializer_list>
|
||||
#include <list>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <memory_resource>
|
||||
#include <ranges>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "test_allocator.h"
|
||||
|
||||
using P = std::pair<int, long>;
|
||||
using PC = std::pair<const int, long>;
|
||||
|
||||
void test_containers() {
|
||||
std::deque<int, test_allocator<int>> ks({1, 2, 1, 2, 2, INT_MAX, 3}, test_allocator<int>(0, 42));
|
||||
std::deque<short, test_allocator<short>> vs({1, 2, 3, 4, 5, 3, 4}, test_allocator<int>(0, 43));
|
||||
std::deque<int, test_allocator<int>> sorted_ks({1, 1, 2, 2, 2, 3, INT_MAX}, test_allocator<int>(0, 42));
|
||||
std::deque<short, test_allocator<short>> sorted_vs({1, 3, 2, 4, 5, 4, 3}, test_allocator<int>(0, 43));
|
||||
const std::pair<int, short> expected[] = {{1, 1}, {1, 3}, {2, 2}, {2, 4}, {2, 5}, {3, 4}, {INT_MAX, 3}};
|
||||
{
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::monotonic_buffer_resource mr2;
|
||||
std::pmr::deque<int> pks(ks.begin(), ks.end(), &mr);
|
||||
std::pmr::deque<short> pvs(vs.begin(), vs.end(), &mr);
|
||||
std::flat_multimap s(std::move(pks), std::move(pvs), &mr2);
|
||||
|
||||
ASSERT_SAME_TYPE(
|
||||
decltype(s), std::flat_multimap<int, short, std::less<int>, std::pmr::deque<int>, std::pmr::deque<short>>);
|
||||
assert(std::ranges::equal(s, expected));
|
||||
assert(s.keys().get_allocator().resource() == &mr2);
|
||||
assert(s.values().get_allocator().resource() == &mr2);
|
||||
}
|
||||
{
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::monotonic_buffer_resource mr2;
|
||||
std::pmr::deque<int> pks(sorted_ks.begin(), sorted_ks.end(), &mr);
|
||||
std::pmr::deque<short> pvs(sorted_vs.begin(), sorted_vs.end(), &mr);
|
||||
std::flat_multimap s(std::sorted_equivalent, std::move(pks), std::move(pvs), &mr2);
|
||||
|
||||
ASSERT_SAME_TYPE(
|
||||
decltype(s), std::flat_multimap<int, short, std::less<int>, std::pmr::deque<int>, std::pmr::deque<short>>);
|
||||
assert(std::ranges::equal(s, expected));
|
||||
assert(s.keys().get_allocator().resource() == &mr2);
|
||||
assert(s.values().get_allocator().resource() == &mr2);
|
||||
}
|
||||
}
|
||||
|
||||
void test_containers_compare() {
|
||||
std::deque<int, test_allocator<int>> ks({1, 2, 1, 2, 2, INT_MAX, 3}, test_allocator<int>(0, 42));
|
||||
std::deque<short, test_allocator<short>> vs({1, 2, 3, 4, 5, 3, 4}, test_allocator<int>(0, 43));
|
||||
std::deque<int, test_allocator<int>> sorted_ks({INT_MAX, 3, 2, 2, 2, 1, 1}, test_allocator<int>(0, 42));
|
||||
std::deque<short, test_allocator<short>> sorted_vs({3, 4, 2, 4, 5, 1, 3}, test_allocator<int>(0, 43));
|
||||
const std::pair<int, short> expected[] = {{INT_MAX, 3}, {3, 4}, {2, 2}, {2, 4}, {2, 5}, {1, 1}, {1, 3}};
|
||||
|
||||
{
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::monotonic_buffer_resource mr2;
|
||||
std::pmr::deque<int> pks(ks.begin(), ks.end(), &mr);
|
||||
std::pmr::deque<short> pvs(vs.begin(), vs.end(), &mr);
|
||||
std::flat_multimap s(std::move(pks), std::move(pvs), std::greater<int>(), &mr2);
|
||||
|
||||
ASSERT_SAME_TYPE(
|
||||
decltype(s), std::flat_multimap<int, short, std::greater<int>, std::pmr::deque<int>, std::pmr::deque<short>>);
|
||||
assert(std::ranges::equal(s, expected));
|
||||
assert(s.keys().get_allocator().resource() == &mr2);
|
||||
assert(s.values().get_allocator().resource() == &mr2);
|
||||
}
|
||||
{
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::monotonic_buffer_resource mr2;
|
||||
std::pmr::deque<int> pks(sorted_ks.begin(), sorted_ks.end(), &mr);
|
||||
std::pmr::deque<short> pvs(sorted_vs.begin(), sorted_vs.end(), &mr);
|
||||
std::flat_multimap s(std::sorted_equivalent, std::move(pks), std::move(pvs), std::greater<int>(), &mr2);
|
||||
|
||||
ASSERT_SAME_TYPE(
|
||||
decltype(s), std::flat_multimap<int, short, std::greater<int>, std::pmr::deque<int>, std::pmr::deque<short>>);
|
||||
assert(std::ranges::equal(s, expected));
|
||||
assert(s.keys().get_allocator().resource() == &mr2);
|
||||
assert(s.values().get_allocator().resource() == &mr2);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test_containers();
|
||||
test_containers_compare();
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap();
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
#include "test_allocator.h"
|
||||
|
||||
struct DefaultCtableComp {
|
||||
explicit DefaultCtableComp() { default_constructed_ = true; }
|
||||
bool operator()(int, int) const { return false; }
|
||||
bool default_constructed_ = false;
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
std::flat_multimap<int, char*> m;
|
||||
assert(m.empty());
|
||||
}
|
||||
{
|
||||
// explicit(false)
|
||||
std::flat_multimap<int, char*> m = {};
|
||||
assert(m.empty());
|
||||
}
|
||||
{
|
||||
std::flat_multimap<int, char*, DefaultCtableComp, std::deque<int, min_allocator<int>>> m;
|
||||
assert(m.empty());
|
||||
assert(m.begin() == m.end());
|
||||
assert(m.key_comp().default_constructed_);
|
||||
}
|
||||
{
|
||||
using A1 = explicit_allocator<int>;
|
||||
using A2 = explicit_allocator<char*>;
|
||||
{
|
||||
std::flat_multimap<int, char*, DefaultCtableComp, std::vector<int, A1>, std::vector<char*, A2>> m;
|
||||
assert(m.empty());
|
||||
assert(m.key_comp().default_constructed_);
|
||||
}
|
||||
{
|
||||
A1 a1;
|
||||
std::flat_multimap<int, int, DefaultCtableComp, std::vector<int, A1>, std::vector<int, A1>> m(a1);
|
||||
assert(m.empty());
|
||||
assert(m.key_comp().default_constructed_);
|
||||
}
|
||||
}
|
||||
{
|
||||
// If an allocator is given, it must be usable by both containers.
|
||||
using A = test_allocator<int>;
|
||||
using M = std::flat_multimap<int, int, std::less<>, std::vector<int>, std::vector<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>);
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap()
|
||||
// noexcept(
|
||||
// is_nothrow_default_constructible_v<key_container_type> &&
|
||||
// is_nothrow_default_constructible_v<mapped_container_type> &&
|
||||
// is_nothrow_default_constructible_v<key_compare>);
|
||||
|
||||
// This tests a conforming extension
|
||||
|
||||
#include <cassert>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "MoveOnly.h"
|
||||
#include "test_allocator.h"
|
||||
|
||||
struct ThrowingCtorComp {
|
||||
ThrowingCtorComp() noexcept(false) {}
|
||||
bool operator()(const auto&, const auto&) const { return false; }
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
#if defined(_LIBCPP_VERSION)
|
||||
{
|
||||
using C = std::flat_multimap<MoveOnly, MoveOnly>;
|
||||
static_assert(std::is_nothrow_default_constructible_v<C>);
|
||||
C c;
|
||||
}
|
||||
{
|
||||
using C =
|
||||
std::flat_multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, std::vector<MoveOnly, test_allocator<MoveOnly>>>;
|
||||
static_assert(std::is_nothrow_default_constructible_v<C>);
|
||||
C c;
|
||||
}
|
||||
#endif // _LIBCPP_VERSION
|
||||
{
|
||||
using C =
|
||||
std::flat_multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, std::vector<MoveOnly, other_allocator<MoveOnly>>>;
|
||||
static_assert(!std::is_nothrow_default_constructible_v<C>);
|
||||
C c;
|
||||
}
|
||||
{
|
||||
using C = std::flat_multimap<MoveOnly, MoveOnly, ThrowingCtorComp>;
|
||||
static_assert(!std::is_nothrow_default_constructible_v<C>);
|
||||
C c;
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// ~flat_multimap();
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "MoveOnly.h"
|
||||
#include "test_allocator.h"
|
||||
|
||||
struct ThrowingDtorComp {
|
||||
bool operator()(const auto&, const auto&) const;
|
||||
~ThrowingDtorComp() noexcept(false) {}
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
using C = std::flat_multimap<MoveOnly, MoveOnly>;
|
||||
static_assert(std::is_nothrow_destructible_v<C>);
|
||||
C c;
|
||||
}
|
||||
{
|
||||
using V = std::vector<MoveOnly, test_allocator<MoveOnly>>;
|
||||
using C = std::flat_multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, V, V>;
|
||||
static_assert(std::is_nothrow_destructible_v<C>);
|
||||
C c;
|
||||
}
|
||||
{
|
||||
using V = std::deque<MoveOnly, other_allocator<MoveOnly>>;
|
||||
using C = std::flat_multimap<MoveOnly, MoveOnly, std::greater<MoveOnly>, V, V>;
|
||||
static_assert(std::is_nothrow_destructible_v<C>);
|
||||
C c;
|
||||
}
|
||||
#if defined(_LIBCPP_VERSION)
|
||||
{
|
||||
using C = std::flat_multimap<MoveOnly, MoveOnly, ThrowingDtorComp>;
|
||||
static_assert(!std::is_nothrow_destructible_v<C>);
|
||||
C c;
|
||||
}
|
||||
#endif // _LIBCPP_VERSION
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
|
||||
// template<class Alloc>
|
||||
// flat_multimap(initializer_list<value_type> il, const Alloc& a);
|
||||
// template<class Alloc>
|
||||
// flat_multimap(initializer_list<value_type> il, const key_compare& comp, const Alloc& a);
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
#include "test_allocator.h"
|
||||
|
||||
#include "../../../test_compare.h"
|
||||
|
||||
struct DefaultCtableComp {
|
||||
explicit DefaultCtableComp() { default_constructed_ = true; }
|
||||
bool operator()(int, int) const { return false; }
|
||||
bool default_constructed_ = false;
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
// The constructors in this subclause shall not participate in overload
|
||||
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
|
||||
// and uses_allocator_v<mapped_container_type, Alloc> is true.
|
||||
|
||||
using C = test_less<int>;
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = other_allocator<int>;
|
||||
using V1 = std::vector<int, A1>;
|
||||
using V2 = std::vector<int, A2>;
|
||||
using M1 = std::flat_multimap<int, int, C, V1, V1>;
|
||||
using M2 = std::flat_multimap<int, int, C, V1, V2>;
|
||||
using M3 = std::flat_multimap<int, int, C, V2, V1>;
|
||||
using IL = std::initializer_list<std::pair<int, int>>;
|
||||
static_assert(std::is_constructible_v<M1, IL, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, IL, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, IL, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, IL, const A2&>);
|
||||
|
||||
static_assert(std::is_constructible_v<M1, IL, const C&, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, IL, const C&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, IL, const C&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, IL, const C&, const A2&>);
|
||||
}
|
||||
|
||||
{
|
||||
// initializer_list<value_type> needs to match exactly
|
||||
using M = std::flat_multimap<int, short>;
|
||||
using C = typename M::key_compare;
|
||||
static_assert(std::is_constructible_v<M, std::initializer_list<std::pair<int, short>>>);
|
||||
static_assert(std::is_constructible_v<M, std::initializer_list<std::pair<int, short>>, C>);
|
||||
static_assert(std::is_constructible_v<M, std::initializer_list<std::pair<int, short>>, C, std::allocator<int>>);
|
||||
static_assert(std::is_constructible_v<M, std::initializer_list<std::pair<int, short>>, std::allocator<int>>);
|
||||
static_assert(!std::is_constructible_v<M, std::initializer_list<std::pair<const int, short>>>);
|
||||
static_assert(!std::is_constructible_v<M, std::initializer_list<std::pair<const int, short>>, C>);
|
||||
static_assert(
|
||||
!std::is_constructible_v<M, std::initializer_list<std::pair<const int, short>>, C, std::allocator<int>>);
|
||||
static_assert(!std::is_constructible_v<M, std::initializer_list<std::pair<const int, short>>, std::allocator<int>>);
|
||||
static_assert(!std::is_constructible_v<M, std::initializer_list<std::pair<const int, const short>>>);
|
||||
static_assert(!std::is_constructible_v<M, std::initializer_list<std::pair<const int, const short>>, C>);
|
||||
static_assert(
|
||||
!std::is_constructible_v<M, std::initializer_list<std::pair<const int, const short>>, C, std::allocator<int>>);
|
||||
static_assert(
|
||||
!std::is_constructible_v<M, std::initializer_list<std::pair<const int, const short>>, std::allocator<int>>);
|
||||
}
|
||||
|
||||
std::pair<int, short> expected[] = {{1, 1}, {2, 2}, {2, 2}, {3, 3}, {3, 3}, {5, 2}};
|
||||
{
|
||||
// flat_multimap(initializer_list<value_type>);
|
||||
using M = std::flat_multimap<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::ranges::equal(m, expected));
|
||||
}
|
||||
{
|
||||
// flat_multimap(initializer_list<value_type>);
|
||||
// explicit(false)
|
||||
using M = std::flat_multimap<int, short>;
|
||||
M m = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
}
|
||||
{
|
||||
// flat_multimap(initializer_list<value_type>);
|
||||
using M = std::flat_multimap<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 + 6));
|
||||
}
|
||||
{
|
||||
using A = explicit_allocator<int>;
|
||||
{
|
||||
// flat_multimap(initializer_list<value_type>);
|
||||
// different comparator
|
||||
using M = std::flat_multimap<int, int, DefaultCtableComp, std::vector<int, A>, std::deque<int, A>>;
|
||||
M m = {{1, 1}, {2, 2}, {3, 3}};
|
||||
assert(m.size() == 3);
|
||||
|
||||
std::pair<int, int> expected1[] = {{1, 1}, {2, 2}, {3, 3}};
|
||||
assert(std::ranges::equal(m, expected1));
|
||||
assert(m.key_comp().default_constructed_);
|
||||
}
|
||||
{
|
||||
// flat_multimap(initializer_list<value_type>, const Allocator&);
|
||||
using M = std::flat_multimap<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 + 6));
|
||||
}
|
||||
}
|
||||
{
|
||||
// flat_multimap(initializer_list<value_type>, const key_compare&);
|
||||
using C = test_less<int>;
|
||||
using M = std::flat_multimap<int, short, C>;
|
||||
auto m = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10));
|
||||
assert(std::ranges::equal(m, expected));
|
||||
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));
|
||||
}
|
||||
{
|
||||
// flat_multimap(initializer_list<value_type>, const key_compare&);
|
||||
// Sorting uses the comparator that was passed in
|
||||
using M = std::flat_multimap<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 + 6));
|
||||
assert(m.key_comp()(2, 1) == true);
|
||||
}
|
||||
{
|
||||
// flat_multimap(initializer_list<value_type> il, const key_compare& comp, const Alloc& a);
|
||||
using A = explicit_allocator<int>;
|
||||
using M = std::flat_multimap<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 + 6));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,154 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// template <class InputIterator>
|
||||
// flat_multimap(InputIterator first, InputIterator last, const key_compare& comp = key_compare());
|
||||
// template<class InputIterator, class Allocator>
|
||||
// flat_multimap(InputIterator first, InputIterator last, const Allocator& a);
|
||||
// template<class InputIterator, class Allocator>
|
||||
// flat_multimap(InputIterator first, InputIterator last, const key_compare& comp, const Allocator& a);
|
||||
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "min_allocator.h"
|
||||
#include "test_allocator.h"
|
||||
#include "test_iterators.h"
|
||||
#include "test_macros.h"
|
||||
#include "../../../test_compare.h"
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
// The constructors in this subclause shall not participate in overload
|
||||
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
|
||||
// and uses_allocator_v<mapped_container_type, Alloc> is true.
|
||||
|
||||
using C = test_less<int>;
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = other_allocator<int>;
|
||||
using V1 = std::vector<int, A1>;
|
||||
using V2 = std::vector<int, A2>;
|
||||
using M1 = std::flat_multimap<int, int, C, V1, V1>;
|
||||
using M2 = std::flat_multimap<int, int, C, V1, V2>;
|
||||
using M3 = std::flat_multimap<int, int, C, V2, V1>;
|
||||
using Iter1 = typename M1::iterator;
|
||||
using Iter2 = typename M2::iterator;
|
||||
using Iter3 = typename M3::iterator;
|
||||
static_assert(std::is_constructible_v<M1, Iter1, Iter1, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, Iter1, Iter1, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, Iter2, Iter2, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, Iter3, Iter3, const A2&>);
|
||||
|
||||
static_assert(std::is_constructible_v<M1, Iter1, Iter1, const C&, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, Iter1, Iter1, const C&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, Iter2, Iter2, const C&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, Iter3, Iter3, const C&, const A2&>);
|
||||
}
|
||||
|
||||
using P = std::pair<int, short>;
|
||||
P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
|
||||
P expected[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {2, 7}, {3, 6}, {3, 8}, {3, 9}};
|
||||
{
|
||||
// flat_multimap(InputIterator , InputIterator)
|
||||
// cpp17_input_iterator
|
||||
using M = std::flat_multimap<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));
|
||||
|
||||
// explicit(false)
|
||||
M m2 = {cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 9)};
|
||||
assert(m2 == m);
|
||||
}
|
||||
{
|
||||
// flat_multimap(InputIterator , InputIterator)
|
||||
// greater
|
||||
using M = std::flat_multimap<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, 3, 3, 2, 2, 2, 1, 1, 1}));
|
||||
LIBCPP_ASSERT((m.values() == std::deque<short>{6, 8, 9, 4, 5, 7, 1, 2, 3}));
|
||||
}
|
||||
{
|
||||
// flat_multimap(InputIterator , InputIterator)
|
||||
// Test when the operands are of array type (also contiguous iterator type)
|
||||
using M = std::flat_multimap<int, short, std::greater<int>, std::vector<int, min_allocator<int>>>;
|
||||
auto m = M(ar, ar);
|
||||
assert(m.empty());
|
||||
}
|
||||
{
|
||||
// flat_multimap(InputIterator , InputIterator, const key_compare&)
|
||||
using C = test_less<int>;
|
||||
using M = std::flat_multimap<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));
|
||||
|
||||
// explicit(false)
|
||||
M m2 = {ar, ar + 9, C(3)};
|
||||
assert(m2 == m);
|
||||
assert(m2.key_comp() == C(3));
|
||||
}
|
||||
{
|
||||
// flat_multimap(InputIterator , InputIterator, const Allocator&)
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = test_allocator<short>;
|
||||
using M = std::flat_multimap<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_multimap(InputIterator , InputIterator, const Allocator&)
|
||||
// explicit(false)
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = test_allocator<short>;
|
||||
using M = std::flat_multimap<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_multimap(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_multimap<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_multimap(InputIterator , InputIterator, const key_compare&, const Allocator&)
|
||||
// explicit(false)
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = test_allocator<short>;
|
||||
using M = std::flat_multimap<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));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap(flat_multimap&&);
|
||||
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "../../../test_compare.h"
|
||||
#include "test_allocator.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
using C = test_less<int>;
|
||||
using A = test_allocator<int>;
|
||||
using M = std::flat_multimap<int, int, C, std::vector<int, A>, std::deque<int, A>>;
|
||||
M mo = M({{1, 1}, {1, 2}, {3, 1}}, C(5), A(7));
|
||||
M m = std::move(mo);
|
||||
assert((m == M{{1, 1}, {1, 2}, {3, 1}}));
|
||||
assert(m.key_comp() == C(5));
|
||||
assert(m.keys().get_allocator() == A(7));
|
||||
assert(m.values().get_allocator() == A(7));
|
||||
|
||||
assert(mo.empty());
|
||||
assert(mo.key_comp() == C(5));
|
||||
assert(mo.keys().get_allocator().get_id() == test_alloc_base::moved_value);
|
||||
assert(mo.values().get_allocator().get_id() == test_alloc_base::moved_value);
|
||||
}
|
||||
{
|
||||
using C = test_less<int>;
|
||||
using A = min_allocator<int>;
|
||||
using M = std::flat_multimap<int, int, C, std::vector<int, A>, std::deque<int, A>>;
|
||||
M mo = M({{1, 1}, {1, 2}, {3, 1}}, C(5), A());
|
||||
M m = std::move(mo);
|
||||
assert((m == M{{1, 1}, {1, 2}, {3, 1}}));
|
||||
assert(m.key_comp() == C(5));
|
||||
assert(m.keys().get_allocator() == A());
|
||||
assert(m.values().get_allocator() == A());
|
||||
|
||||
assert(mo.empty());
|
||||
assert(mo.key_comp() == C(5));
|
||||
assert(m.keys().get_allocator() == A());
|
||||
assert(m.values().get_allocator() == A());
|
||||
}
|
||||
{
|
||||
// A moved-from flat_multimap maintains its class invariant in the presence of moved-from comparators.
|
||||
using M = std::flat_multimap<int, int, std::function<bool(int, int)>>;
|
||||
M mo = M({{1, 1}, {1, 2}, {3, 1}}, std::less<int>());
|
||||
M m = std::move(mo);
|
||||
assert(m.size() == 3);
|
||||
assert(std::is_sorted(m.begin(), m.end(), m.value_comp()));
|
||||
assert(m.key_comp()(1, 2) == true);
|
||||
|
||||
assert(std::is_sorted(mo.begin(), mo.end(), mo.value_comp()));
|
||||
LIBCPP_ASSERT(m.key_comp()(1, 2) == true);
|
||||
LIBCPP_ASSERT(mo.empty());
|
||||
mo.insert({{1, 1}, {1, 2}, {3, 1}}); // insert has no preconditions
|
||||
assert(m == mo);
|
||||
}
|
||||
{
|
||||
// moved-from object maintains invariant if one of underlying container does not clear after move
|
||||
using M = std::flat_multimap<int, int, std::less<>, std::vector<int>, CopyOnlyVector<int>>;
|
||||
M m1 = M({1, 1, 3}, {1, 2, 3});
|
||||
M m2 = std::move(m1);
|
||||
assert(m2.size() == 3);
|
||||
check_invariant(m1);
|
||||
LIBCPP_ASSERT(m1.empty());
|
||||
LIBCPP_ASSERT(m1.keys().size() == 0);
|
||||
LIBCPP_ASSERT(m1.values().size() == 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap(flat_multimap&&, const allocator_type&);
|
||||
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#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_multimap<int, int, C, V1, V1>;
|
||||
using M2 = std::flat_multimap<int, int, C, V1, V2>;
|
||||
using M3 = std::flat_multimap<int, int, C, V2, V1>;
|
||||
static_assert(std::is_constructible_v<M1, 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&>);
|
||||
}
|
||||
{
|
||||
std::pair<int, int> expected[] = {{1, 1}, {1, 2}, {2, 3}, {2, 2}, {3, 1}};
|
||||
using C = test_less<int>;
|
||||
using A = test_allocator<int>;
|
||||
using M = std::flat_multimap<int, int, C, std::vector<int, A>, std::deque<int, A>>;
|
||||
auto mo = M(expected, expected + 5, C(5), A(7));
|
||||
auto m = M(std::move(mo), A(3));
|
||||
|
||||
assert(m.key_comp() == C(5));
|
||||
assert(m.size() == 5);
|
||||
auto [keys, values] = std::move(m).extract();
|
||||
assert(keys.get_allocator() == A(3));
|
||||
assert(values.get_allocator() == A(3));
|
||||
assert(std::ranges::equal(keys, expected | std::views::elements<0>));
|
||||
assert(std::ranges::equal(values, expected | std::views::elements<1>));
|
||||
|
||||
// The original flat_multimap is moved-from.
|
||||
assert(std::is_sorted(mo.begin(), mo.end(), mo.value_comp()));
|
||||
assert(mo.empty());
|
||||
assert(mo.key_comp() == C(5));
|
||||
assert(mo.keys().get_allocator() == A(7));
|
||||
assert(mo.values().get_allocator() == A(7));
|
||||
}
|
||||
{
|
||||
// moved-from object maintains invariant if one of underlying container does not clear after move
|
||||
using M = std::flat_multimap<int, int, std::less<>, std::vector<int>, CopyOnlyVector<int>>;
|
||||
M m1 = M({1, 1, 3}, {1, 2, 3});
|
||||
M m2(std::move(m1), std::allocator<int>{});
|
||||
assert(m2.size() == 3);
|
||||
check_invariant(m1);
|
||||
LIBCPP_ASSERT(m1.empty());
|
||||
LIBCPP_ASSERT(m1.keys().size() == 0);
|
||||
LIBCPP_ASSERT(m1.values().size() == 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap& operator=(flat_multimap&&);
|
||||
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "MoveOnly.h"
|
||||
#include "../../../test_compare.h"
|
||||
#include "test_allocator.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
using C = test_less<int>;
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = test_allocator<char>;
|
||||
using M = std::flat_multimap<int, char, C, std::vector<int, A1>, std::vector<char, A2>>;
|
||||
M mo = M({{1, 1}, {1, 3}, {3, 2}}, C(5), A1(7));
|
||||
M m = M({}, C(3), A1(7));
|
||||
m = std::move(mo);
|
||||
assert((m == M{{1, 1}, {1, 3}, {3, 2}}));
|
||||
assert(m.key_comp() == C(5));
|
||||
auto [ks, vs] = std::move(m).extract();
|
||||
assert(ks.get_allocator() == A1(7));
|
||||
assert(vs.get_allocator() == A2(7));
|
||||
assert(mo.empty());
|
||||
}
|
||||
{
|
||||
using C = test_less<int>;
|
||||
using A1 = other_allocator<int>;
|
||||
using A2 = other_allocator<char>;
|
||||
using M = std::flat_multimap<int, char, C, std::deque<int, A1>, std::deque<char, A2>>;
|
||||
M mo = M({{4, 5}, {4, 4}}, C(5), A1(7));
|
||||
M m = M({{1, 1}, {1, 2}, {1, 3}, {4, 4}}, C(3), A1(7));
|
||||
m = std::move(mo);
|
||||
assert((m == M{{4, 5}, {4, 4}}));
|
||||
assert(m.key_comp() == C(5));
|
||||
auto [ks, vs] = std::move(m).extract();
|
||||
assert(ks.get_allocator() == A1(7));
|
||||
assert(vs.get_allocator() == A2(7));
|
||||
assert(mo.empty());
|
||||
}
|
||||
{
|
||||
using A = min_allocator<int>;
|
||||
using M = std::flat_multimap<int, int, std::greater<int>, std::vector<int, A>, std::vector<int, A>>;
|
||||
M mo = M({{5, 1}, {5, 2}, {3, 3}}, A());
|
||||
M m = M({{4, 4}, {4, 3}, {4, 2}, {1, 1}}, A());
|
||||
m = std::move(mo);
|
||||
assert((m == M{{5, 1}, {5, 2}, {3, 3}}));
|
||||
auto [ks, vs] = std::move(m).extract();
|
||||
assert(ks.get_allocator() == A());
|
||||
assert(vs.get_allocator() == A());
|
||||
assert(mo.empty());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap& operator=(flat_multimap&&);
|
||||
// Preserves the class invariant for the moved-from flat_multimap.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <compare>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
|
||||
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) {
|
||||
value_ = rhs.value_;
|
||||
rhs.value_ = -rhs.value_;
|
||||
return *this;
|
||||
}
|
||||
~MoveNegates() = default;
|
||||
auto operator<=>(const MoveNegates&) const = default;
|
||||
};
|
||||
|
||||
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) {
|
||||
value_ = rhs.value_;
|
||||
rhs.value_ = 0;
|
||||
return *this;
|
||||
}
|
||||
~MoveClears() = default;
|
||||
auto operator<=>(const MoveClears&) const = default;
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
const std::pair<int, int> expected[] = {{1, 1}, {1, 2}, {3, 3}, {3, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}};
|
||||
using M = std::flat_multimap<MoveNegates, int, std::less<MoveNegates>, std::vector<MoveNegates>>;
|
||||
M m = M(expected, expected + 8);
|
||||
M m2 = M(expected, expected + 3);
|
||||
|
||||
m2 = std::move(m);
|
||||
|
||||
assert(std::equal(m2.begin(), m2.end(), expected, expected + 8));
|
||||
LIBCPP_ASSERT(m.empty());
|
||||
check_invariant(m);
|
||||
m.insert({1, 1});
|
||||
m.insert({2, 2});
|
||||
assert(m.contains(1));
|
||||
assert(m.find(2) != m.end());
|
||||
}
|
||||
{
|
||||
const std::pair<int, int> expected[] = {{1, 1}, {1, 2}, {3, 3}, {4, 4}, {5, 5}, {5, 6}, {7, 7}, {8, 8}};
|
||||
using M = std::flat_multimap<MoveClears, int, std::less<MoveClears>, std::vector<MoveClears>>;
|
||||
M m = M(expected, expected + 8);
|
||||
M m2 = M(expected, expected + 3);
|
||||
|
||||
m2 = std::move(m);
|
||||
|
||||
assert(std::equal(m2.begin(), m2.end(), expected, expected + 8));
|
||||
LIBCPP_ASSERT(m.empty());
|
||||
check_invariant(m);
|
||||
m.insert({1, 1});
|
||||
m.insert({2, 2});
|
||||
assert(m.contains(1));
|
||||
assert(m.find(2) != m.end());
|
||||
}
|
||||
{
|
||||
// moved-from object maintains invariant if one of underlying container does not clear after move
|
||||
using M = std::flat_multimap<int, int, std::less<>, std::vector<int>, CopyOnlyVector<int>>;
|
||||
M m1 = M({1, 1, 3}, {1, 2, 3});
|
||||
M m2 = M({1, 1}, {1, 2});
|
||||
m2 = std::move(m1);
|
||||
assert(m2.size() == 3);
|
||||
check_invariant(m1);
|
||||
LIBCPP_ASSERT(m1.empty());
|
||||
LIBCPP_ASSERT(m1.keys().size() == 0);
|
||||
LIBCPP_ASSERT(m1.values().size() == 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap& operator=(flat_multimap&& c)
|
||||
// noexcept(
|
||||
// is_nothrow_move_assignable<key_container_type>::value &&
|
||||
// is_nothrow_move_assignable<mapped_container_type>::value &&
|
||||
// is_nothrow_copy_assignable<key_compare>::value);
|
||||
|
||||
// This tests a conforming extension
|
||||
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <memory_resource>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "MoveOnly.h"
|
||||
#include "test_allocator.h"
|
||||
#include "test_macros.h"
|
||||
|
||||
struct MoveSensitiveComp {
|
||||
MoveSensitiveComp() noexcept(false) = default;
|
||||
MoveSensitiveComp(const MoveSensitiveComp&) noexcept(false) = default;
|
||||
MoveSensitiveComp(MoveSensitiveComp&& rhs) { rhs.is_moved_from_ = true; }
|
||||
MoveSensitiveComp& operator=(const MoveSensitiveComp&) noexcept = default;
|
||||
MoveSensitiveComp& operator=(MoveSensitiveComp&& rhs) {
|
||||
rhs.is_moved_from_ = true;
|
||||
return *this;
|
||||
}
|
||||
bool operator()(const auto&, const auto&) const { return false; }
|
||||
bool is_moved_from_ = false;
|
||||
};
|
||||
|
||||
struct MoveThrowsComp {
|
||||
MoveThrowsComp(MoveThrowsComp&&) noexcept(false);
|
||||
MoveThrowsComp(const MoveThrowsComp&) noexcept(true);
|
||||
MoveThrowsComp& operator=(MoveThrowsComp&&) noexcept(false);
|
||||
MoveThrowsComp& operator=(const MoveThrowsComp&) noexcept(true);
|
||||
bool operator()(const auto&, const auto&) const;
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
using C = std::flat_multimap<int, int>;
|
||||
LIBCPP_STATIC_ASSERT(std::is_nothrow_move_assignable_v<C>);
|
||||
}
|
||||
{
|
||||
using C =
|
||||
std::flat_multimap<MoveOnly,
|
||||
int,
|
||||
std::less<MoveOnly>,
|
||||
std::vector<MoveOnly, test_allocator<MoveOnly>>,
|
||||
std::vector<int, test_allocator<int>>>;
|
||||
static_assert(!std::is_nothrow_move_assignable_v<C>);
|
||||
}
|
||||
{
|
||||
using C =
|
||||
std::flat_multimap<int,
|
||||
MoveOnly,
|
||||
std::less<int>,
|
||||
std::vector<int, test_allocator<int>>,
|
||||
std::vector<MoveOnly, test_allocator<MoveOnly>>>;
|
||||
static_assert(!std::is_nothrow_move_assignable_v<C>);
|
||||
}
|
||||
{
|
||||
using C =
|
||||
std::flat_multimap<MoveOnly,
|
||||
int,
|
||||
std::less<MoveOnly>,
|
||||
std::vector<MoveOnly, other_allocator<MoveOnly>>,
|
||||
std::vector<int, other_allocator<int>>>;
|
||||
LIBCPP_STATIC_ASSERT(std::is_nothrow_move_assignable_v<C>);
|
||||
}
|
||||
{
|
||||
using C =
|
||||
std::flat_multimap<int,
|
||||
MoveOnly,
|
||||
std::less<int>,
|
||||
std::vector<int, other_allocator<int>>,
|
||||
std::vector<MoveOnly, other_allocator<MoveOnly>>>;
|
||||
LIBCPP_STATIC_ASSERT(std::is_nothrow_move_assignable_v<C>);
|
||||
}
|
||||
{
|
||||
// Test with a comparator that throws on move-assignment.
|
||||
using C = std::flat_multimap<int, int, MoveThrowsComp>;
|
||||
LIBCPP_STATIC_ASSERT(!std::is_nothrow_move_assignable_v<C>);
|
||||
}
|
||||
{
|
||||
// Test with a container that throws on move-assignment.
|
||||
using C = std::flat_multimap<int, int, std::less<int>, std::pmr::vector<int>, std::vector<int>>;
|
||||
static_assert(!std::is_nothrow_move_assignable_v<C>);
|
||||
}
|
||||
{
|
||||
// Test with a container that throws on move-assignment.
|
||||
using C = std::flat_multimap<int, int, std::less<int>, std::vector<int>, std::pmr::vector<int>>;
|
||||
static_assert(!std::is_nothrow_move_assignable_v<C>);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
// UNSUPPORTED: no-exceptions
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap(flat_multimap&& s);
|
||||
// If any member function in [flat.multimap.defn] exits via an exception, the invariant is restored.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
|
||||
static int countdown = 0;
|
||||
|
||||
struct EvilContainer : std::vector<int> {
|
||||
EvilContainer() = default;
|
||||
EvilContainer(EvilContainer&& rhs) {
|
||||
// Throw on move-construction.
|
||||
if (--countdown == 0) {
|
||||
rhs.insert(rhs.end(), 0);
|
||||
rhs.insert(rhs.end(), 0);
|
||||
throw 42;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
using M = std::flat_multimap<int, int, std::less<int>, EvilContainer, std::vector<int>>;
|
||||
M mo = {{1, 1}, {1, 2}, {3, 3}};
|
||||
countdown = 1;
|
||||
try {
|
||||
M m = std::move(mo);
|
||||
assert(false); // not reached
|
||||
} catch (int x) {
|
||||
assert(x == 42);
|
||||
}
|
||||
// The source flat_multimap maintains its class invariant.
|
||||
check_invariant(mo);
|
||||
LIBCPP_ASSERT(mo.empty());
|
||||
}
|
||||
{
|
||||
using M = std::flat_multimap<int, int, std::less<int>, std::vector<int>, EvilContainer>;
|
||||
M mo = {{1, 1}, {1, 2}, {3, 3}};
|
||||
countdown = 1;
|
||||
try {
|
||||
M m = std::move(mo);
|
||||
assert(false); // not reached
|
||||
} catch (int x) {
|
||||
assert(x == 42);
|
||||
}
|
||||
// The source flat_multimap maintains its class invariant.
|
||||
check_invariant(mo);
|
||||
LIBCPP_ASSERT(mo.empty());
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap(flat_multimap&&)
|
||||
// noexcept(is_nothrow_move_constructible<key_container_type>::value &&
|
||||
// is_nothrow_move_constructible<mapped_container_type>::value &&
|
||||
// is_nothrow_copy_constructible<key_compare>::value);
|
||||
|
||||
// This tests a conforming extension
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "MoveOnly.h"
|
||||
#include "test_allocator.h"
|
||||
|
||||
template <class T>
|
||||
struct ThrowingMoveAllocator {
|
||||
using value_type = T;
|
||||
explicit ThrowingMoveAllocator() = default;
|
||||
ThrowingMoveAllocator(const ThrowingMoveAllocator&) = default;
|
||||
ThrowingMoveAllocator(ThrowingMoveAllocator&&) noexcept(false) {}
|
||||
T* allocate(std::ptrdiff_t n) { return std::allocator<T>().allocate(n); }
|
||||
void deallocate(T* p, std::ptrdiff_t n) { return std::allocator<T>().deallocate(p, n); }
|
||||
friend bool operator==(ThrowingMoveAllocator, ThrowingMoveAllocator) = default;
|
||||
};
|
||||
|
||||
struct ThrowingMoveComp {
|
||||
ThrowingMoveComp() = default;
|
||||
ThrowingMoveComp(const ThrowingMoveComp&) noexcept(true) {}
|
||||
ThrowingMoveComp(ThrowingMoveComp&&) noexcept(false) {}
|
||||
bool operator()(const auto&, const auto&) const { return false; }
|
||||
};
|
||||
|
||||
struct MoveSensitiveComp {
|
||||
MoveSensitiveComp() noexcept(false) = default;
|
||||
MoveSensitiveComp(const MoveSensitiveComp&) noexcept = default;
|
||||
MoveSensitiveComp(MoveSensitiveComp&& rhs) { rhs.is_moved_from_ = true; }
|
||||
MoveSensitiveComp& operator=(const MoveSensitiveComp&) noexcept(false) = default;
|
||||
MoveSensitiveComp& operator=(MoveSensitiveComp&& rhs) {
|
||||
rhs.is_moved_from_ = true;
|
||||
return *this;
|
||||
}
|
||||
bool operator()(const auto&, const auto&) const { return false; }
|
||||
bool is_moved_from_ = false;
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
using C = std::flat_multimap<int, int>;
|
||||
LIBCPP_STATIC_ASSERT(std::is_nothrow_move_constructible_v<C>);
|
||||
C c;
|
||||
C d = std::move(c);
|
||||
}
|
||||
{
|
||||
using C = std::flat_multimap<int, int, std::less<int>, std::deque<int, test_allocator<int>>>;
|
||||
LIBCPP_STATIC_ASSERT(std::is_nothrow_move_constructible_v<C>);
|
||||
C c;
|
||||
C d = std::move(c);
|
||||
}
|
||||
#if _LIBCPP_VERSION
|
||||
{
|
||||
// Container fails to be nothrow-move-constructible; this relies on libc++'s support for non-nothrow-copyable allocators
|
||||
using C =
|
||||
std::flat_multimap<int, int, std::less<int>, std::deque<int, ThrowingMoveAllocator<int>>, std::vector<int>>;
|
||||
static_assert(!std::is_nothrow_move_constructible_v<std::deque<int, ThrowingMoveAllocator<int>>>);
|
||||
static_assert(!std::is_nothrow_move_constructible_v<C>);
|
||||
C c;
|
||||
C d = std::move(c);
|
||||
}
|
||||
{
|
||||
// Container fails to be nothrow-move-constructible; this relies on libc++'s support for non-nothrow-copyable allocators
|
||||
using C =
|
||||
std::flat_multimap<int, int, std::less<int>, std::vector<int>, std::deque<int, ThrowingMoveAllocator<int>>>;
|
||||
static_assert(!std::is_nothrow_move_constructible_v<std::deque<int, ThrowingMoveAllocator<int>>>);
|
||||
static_assert(!std::is_nothrow_move_constructible_v<C>);
|
||||
C c;
|
||||
C d = std::move(c);
|
||||
}
|
||||
#endif // _LIBCPP_VERSION
|
||||
{
|
||||
// Comparator fails to be nothrow-move-constructible
|
||||
using C = std::flat_multimap<int, int, ThrowingMoveComp>;
|
||||
static_assert(!std::is_nothrow_move_constructible_v<C>);
|
||||
C c;
|
||||
C d = std::move(c);
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,361 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
// UNSUPPORTED: availability-pmr-missing
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// Test various constructors with pmr
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <memory_resource>
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "test_iterators.h"
|
||||
#include "test_macros.h"
|
||||
#include "test_allocator.h"
|
||||
#include "../../../test_compare.h"
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
// flat_multimap(const Allocator& a);
|
||||
using M = std::flat_multimap<int, short, std::less<int>, std::pmr::vector<int>, std::pmr::vector<short>>;
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::polymorphic_allocator<int> pa = &mr;
|
||||
auto m1 = M(pa);
|
||||
assert(m1.empty());
|
||||
assert(m1.keys().get_allocator() == pa);
|
||||
assert(m1.values().get_allocator() == pa);
|
||||
auto m2 = M(&mr);
|
||||
assert(m2.empty());
|
||||
assert(m2.keys().get_allocator() == pa);
|
||||
assert(m2.values().get_allocator() == pa);
|
||||
}
|
||||
{
|
||||
// flat_multimap(const key_compare& comp, const Alloc& a);
|
||||
using M = std::flat_multimap<int, int, std::function<bool(int, int)>, std::pmr::vector<int>, std::pmr::vector<int>>;
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::vector<M> vm(&mr);
|
||||
vm.emplace_back(std::greater<int>());
|
||||
assert(vm[0] == M{});
|
||||
assert(vm[0].key_comp()(2, 1) == true);
|
||||
assert(vm[0].value_comp()({2, 0}, {1, 0}) == true);
|
||||
assert(vm[0].keys().get_allocator().resource() == &mr);
|
||||
assert(vm[0].values().get_allocator().resource() == &mr);
|
||||
}
|
||||
{
|
||||
// flat_multimap(const key_container_type& key_cont, const mapped_container_type& mapped_cont,
|
||||
// const Allocator& a);
|
||||
using M = std::flat_multimap<int, int, std::less<int>, std::pmr::vector<int>, std::pmr::vector<int>>;
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::vector<M> vm(&mr);
|
||||
std::pmr::vector<int> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
|
||||
std::pmr::vector<int> vs = {1, 1, 1, 2, 2, 3, 2, 3, 3};
|
||||
assert(ks.get_allocator().resource() != &mr);
|
||||
assert(vs.get_allocator().resource() != &mr);
|
||||
vm.emplace_back(ks, vs);
|
||||
assert(ks.size() == 9); // ks' value is unchanged, since it was an lvalue above
|
||||
assert(vs.size() == 9); // vs' value is unchanged, since it was an lvalue above
|
||||
assert((vm[0] == M{{1, 1}, {1, 1}, {1, 1}, {2, 2}, {2, 2}, {2, 2}, {3, 3}, {3, 3}, {3, 3}}));
|
||||
assert(vm[0].keys().get_allocator().resource() == &mr);
|
||||
assert(vm[0].values().get_allocator().resource() == &mr);
|
||||
}
|
||||
{
|
||||
// flat_multimap(const flat_multimap&, const allocator_type&);
|
||||
using C = test_less<int>;
|
||||
using M = std::flat_multimap<int, int, C, std::pmr::vector<int>, std::pmr::vector<int>>;
|
||||
std::pmr::monotonic_buffer_resource mr1;
|
||||
std::pmr::monotonic_buffer_resource mr2;
|
||||
M mo = M({1, 2, 1}, {2, 2, 1}, C(5), &mr1);
|
||||
M m = {mo, &mr2}; // also test the implicitness of this constructor
|
||||
|
||||
assert(m.key_comp() == C(5));
|
||||
assert((m.keys() == std::pmr::vector<int>{1, 1, 2}));
|
||||
assert((m.values() == std::pmr::vector<int>{2, 1, 2}));
|
||||
assert(m.keys().get_allocator().resource() == &mr2);
|
||||
assert(m.values().get_allocator().resource() == &mr2);
|
||||
|
||||
// mo is unchanged
|
||||
assert(mo.key_comp() == C(5));
|
||||
assert((mo.keys() == std::pmr::vector<int>{1, 1, 2}));
|
||||
assert((mo.values() == std::pmr::vector<int>{2, 1, 2}));
|
||||
assert(mo.keys().get_allocator().resource() == &mr1);
|
||||
assert(mo.values().get_allocator().resource() == &mr1);
|
||||
}
|
||||
{
|
||||
// flat_multimap(const flat_multimap&, const allocator_type&);
|
||||
using M = std::flat_multimap<int, int, std::less<>, std::pmr::vector<int>, std::pmr::deque<int>>;
|
||||
std::pmr::vector<M> vs;
|
||||
M m = {{1, 2}, {1, 2}, {3, 1}};
|
||||
vs.push_back(m);
|
||||
assert(vs[0] == m);
|
||||
}
|
||||
{
|
||||
// flat_multimap& operator=(const flat_multimap& m);
|
||||
// pmr allocator is not propagated
|
||||
using M = std::flat_multimap<int, int, std::less<>, std::pmr::deque<int>, std::pmr::vector<int>>;
|
||||
std::pmr::monotonic_buffer_resource mr1;
|
||||
std::pmr::monotonic_buffer_resource mr2;
|
||||
M mo = M({{1, 1}, {1, 2}, {3, 3}}, &mr1);
|
||||
M m = M({{4, 4}, {4, 5}}, &mr2);
|
||||
m = mo;
|
||||
assert((m == M{{1, 1}, {1, 2}, {3, 3}}));
|
||||
assert(m.keys().get_allocator().resource() == &mr2);
|
||||
assert(m.values().get_allocator().resource() == &mr2);
|
||||
|
||||
// mo is unchanged
|
||||
assert((mo == M{{1, 1}, {1, 2}, {3, 3}}));
|
||||
assert(mo.keys().get_allocator().resource() == &mr1);
|
||||
}
|
||||
{
|
||||
// flat_multimap(const flat_multimap& m);
|
||||
using C = test_less<int>;
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
using M = std::flat_multimap<int, int, C, std::pmr::vector<int>, std::pmr::vector<int>>;
|
||||
auto mo = M({{1, 1}, {1, 2}, {3, 3}}, C(5), &mr);
|
||||
auto m = mo;
|
||||
|
||||
assert(m.key_comp() == C(5));
|
||||
assert((m == M{{1, 1}, {1, 2}, {3, 3}}));
|
||||
auto [ks, vs] = std::move(m).extract();
|
||||
assert(ks.get_allocator().resource() == std::pmr::get_default_resource());
|
||||
assert(vs.get_allocator().resource() == std::pmr::get_default_resource());
|
||||
|
||||
// mo is unchanged
|
||||
assert(mo.key_comp() == C(5));
|
||||
assert((mo == M{{1, 1}, {1, 2}, {3, 3}}));
|
||||
auto [kso, vso] = std::move(mo).extract();
|
||||
assert(kso.get_allocator().resource() == &mr);
|
||||
assert(vso.get_allocator().resource() == &mr);
|
||||
}
|
||||
{
|
||||
// flat_multimap(initializer_list<value_type> il, const Alloc& a);
|
||||
using M = std::flat_multimap<int, int, std::less<int>, std::pmr::vector<int>, std::pmr::vector<int>>;
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::vector<M> vm(&mr);
|
||||
std::initializer_list<M::value_type> il = {{3, 3}, {1, 1}, {4, 4}, {1, 1}, {5, 5}};
|
||||
vm.emplace_back(il);
|
||||
assert((vm[0] == M{{1, 1}, {1, 1}, {3, 3}, {4, 4}, {5, 5}}));
|
||||
assert(vm[0].keys().get_allocator().resource() == &mr);
|
||||
assert(vm[0].values().get_allocator().resource() == &mr);
|
||||
}
|
||||
{
|
||||
// flat_multimap(initializer_list<value_type> il, const key_compare& comp, const Alloc& a);
|
||||
using C = test_less<int>;
|
||||
using M = std::flat_multimap<int, int, C, std::pmr::vector<int>, std::pmr::deque<int>>;
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::vector<M> vm(&mr);
|
||||
std::initializer_list<M::value_type> il = {{3, 3}, {1, 1}, {4, 4}, {1, 1}, {5, 5}};
|
||||
vm.emplace_back(il, C(5));
|
||||
assert((vm[0] == M{{1, 1}, {1, 1}, {3, 3}, {4, 4}, {5, 5}}));
|
||||
assert(vm[0].keys().get_allocator().resource() == &mr);
|
||||
assert(vm[0].values().get_allocator().resource() == &mr);
|
||||
assert(vm[0].key_comp() == C(5));
|
||||
}
|
||||
{
|
||||
// flat_multimap(InputIterator first, InputIterator last, const Allocator& a);
|
||||
using P = std::pair<int, short>;
|
||||
P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
|
||||
P expected[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {2, 7}, {3, 6}, {3, 8}, {3, 9}};
|
||||
{
|
||||
// cpp17 iterator
|
||||
using M = std::flat_multimap<int, short, std::less<int>, std::pmr::vector<int>, std::pmr::vector<short>>;
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::vector<M> vm(&mr);
|
||||
vm.emplace_back(cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 9));
|
||||
assert(std::ranges::equal(vm[0].keys(), expected | std::views::elements<0>));
|
||||
LIBCPP_ASSERT(std::ranges::equal(vm[0], expected));
|
||||
assert(vm[0].keys().get_allocator().resource() == &mr);
|
||||
assert(vm[0].values().get_allocator().resource() == &mr);
|
||||
}
|
||||
{
|
||||
using M = std::flat_multimap<int, short, std::less<int>, std::pmr::vector<int>, std::pmr::vector<short>>;
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::vector<M> vm(&mr);
|
||||
vm.emplace_back(ar, ar);
|
||||
assert(vm[0].empty());
|
||||
assert(vm[0].keys().get_allocator().resource() == &mr);
|
||||
assert(vm[0].values().get_allocator().resource() == &mr);
|
||||
}
|
||||
}
|
||||
{
|
||||
// flat_multimap(flat_multimap&&, const allocator_type&);
|
||||
std::pair<int, int> expected[] = {{1, 1}, {1, 1}, {2, 2}, {3, 1}};
|
||||
using C = test_less<int>;
|
||||
using M = std::flat_multimap<int, int, C, std::pmr::vector<int>, std::pmr::deque<int>>;
|
||||
std::pmr::monotonic_buffer_resource mr1;
|
||||
std::pmr::monotonic_buffer_resource mr2;
|
||||
M mo = M({{1, 1}, {3, 1}, {1, 1}, {2, 2}}, C(5), &mr1);
|
||||
M m = {std::move(mo), &mr2}; // also test the implicitness of this constructor
|
||||
|
||||
assert(m.key_comp() == C(5));
|
||||
assert(m.size() == 4);
|
||||
assert(m.keys().get_allocator().resource() == &mr2);
|
||||
assert(m.values().get_allocator().resource() == &mr2);
|
||||
assert(std::ranges::equal(m, expected));
|
||||
|
||||
// The original flat_multimap is moved-from.
|
||||
assert(std::is_sorted(mo.begin(), mo.end(), mo.value_comp()));
|
||||
assert(mo.key_comp() == C(5));
|
||||
assert(mo.keys().get_allocator().resource() == &mr1);
|
||||
assert(mo.values().get_allocator().resource() == &mr1);
|
||||
}
|
||||
{
|
||||
// flat_multimap(flat_multimap&&, const allocator_type&);
|
||||
using M = std::flat_multimap<int, int, std::less<>, std::pmr::deque<int>, std::pmr::vector<int>>;
|
||||
std::pmr::vector<M> vs;
|
||||
M m = {{1, 1}, {3, 1}, {1, 1}, {2, 2}};
|
||||
vs.push_back(std::move(m));
|
||||
assert((vs[0].keys() == std::pmr::deque<int>{1, 1, 2, 3}));
|
||||
assert((vs[0].values() == std::pmr::vector<int>{1, 1, 2, 1}));
|
||||
}
|
||||
{
|
||||
// flat_multimap& operator=(flat_multimap&&);
|
||||
using M = std::
|
||||
flat_multimap<std::pmr::string, int, std::less<>, std::pmr::vector<std::pmr::string>, std::pmr::vector<int>>;
|
||||
std::pmr::monotonic_buffer_resource mr1;
|
||||
std::pmr::monotonic_buffer_resource mr2;
|
||||
M mo = M({{"short", 1},
|
||||
{"very long string that definitely won't fit in the SSO buffer and therefore becomes empty on move", 2}},
|
||||
&mr1);
|
||||
M m = M({{"don't care", 3}}, &mr2);
|
||||
m = std::move(mo);
|
||||
assert(m.size() == 2);
|
||||
assert(std::is_sorted(m.begin(), m.end(), m.value_comp()));
|
||||
assert(m.begin()->first.get_allocator().resource() == &mr2);
|
||||
|
||||
assert(std::is_sorted(mo.begin(), mo.end(), mo.value_comp()));
|
||||
mo.insert({"foo", 1});
|
||||
assert(mo.begin()->first.get_allocator().resource() == &mr1);
|
||||
}
|
||||
{
|
||||
// flat_multimap(from_range_t, R&&, const Alloc&);
|
||||
using P = std::pair<int, short>;
|
||||
P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
|
||||
P expected[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {2, 7}, {3, 6}, {3, 8}, {3, 9}};
|
||||
{
|
||||
// input_range
|
||||
using M = std::flat_multimap<int, short, std::less<int>, std::pmr::vector<int>, std::pmr::vector<short>>;
|
||||
using Iter = cpp20_input_iterator<const P*>;
|
||||
using Sent = sentinel_wrapper<Iter>;
|
||||
using R = std::ranges::subrange<Iter, Sent>;
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::vector<M> vm(&mr);
|
||||
vm.emplace_back(std::from_range, R(Iter(ar), Sent(Iter(ar + 9))));
|
||||
assert(std::ranges::equal(vm[0].keys(), expected | std::views::elements<0>));
|
||||
LIBCPP_ASSERT(std::ranges::equal(vm[0], expected));
|
||||
assert(vm[0].keys().get_allocator().resource() == &mr);
|
||||
assert(vm[0].values().get_allocator().resource() == &mr);
|
||||
}
|
||||
{
|
||||
using M = std::flat_multimap<int, short, std::less<int>, std::pmr::vector<int>, std::pmr::vector<short>>;
|
||||
using R = std::ranges::subrange<const P*>;
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::vector<M> vm(&mr);
|
||||
vm.emplace_back(std::from_range, R(ar, ar));
|
||||
assert(vm[0].empty());
|
||||
assert(vm[0].keys().get_allocator().resource() == &mr);
|
||||
assert(vm[0].values().get_allocator().resource() == &mr);
|
||||
}
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, const key_container_type& key_cont,
|
||||
// const mapped_container_type& mapped_cont, const Alloc& a);
|
||||
using M = std::flat_multimap<int, int, std::less<int>, std::pmr::vector<int>, std::pmr::vector<int>>;
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::vector<M> vm(&mr);
|
||||
std::pmr::vector<int> ks = {1, 1, 4, 10};
|
||||
std::pmr::vector<int> vs = {4, 3, 2, 1};
|
||||
vm.emplace_back(std::sorted_equivalent, ks, vs);
|
||||
assert(!ks.empty()); // it was an lvalue above
|
||||
assert(!vs.empty()); // it was an lvalue above
|
||||
assert((vm[0] == M{{1, 4}, {1, 3}, {4, 2}, {10, 1}}));
|
||||
assert(vm[0].keys().get_allocator().resource() == &mr);
|
||||
assert(vm[0].values().get_allocator().resource() == &mr);
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, const key_container_type& key_cont,
|
||||
// const mapped_container_type& mapped_cont, const Alloc& a);
|
||||
using M = std::flat_multimap<int, int, std::less<int>, std::pmr::vector<int>, std::pmr::vector<int>>;
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::vector<M> vm(&mr);
|
||||
std::pmr::vector<int> ks({1, 1, 4, 10}, &mr);
|
||||
std::pmr::vector<int> vs({4, 3, 2, 1}, &mr);
|
||||
vm.emplace_back(std::sorted_equivalent, ks, vs);
|
||||
assert((vm[0] == M{{1, 4}, {1, 3}, {4, 2}, {10, 1}}));
|
||||
assert(vm[0].keys().get_allocator().resource() == &mr);
|
||||
assert(vm[0].values().get_allocator().resource() == &mr);
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, initializer_list<value_type> il, const Alloc& a);
|
||||
// cpp_17
|
||||
using C = test_less<int>;
|
||||
using M = std::flat_multimap<int, int, C, std::pmr::vector<int>, std::pmr::vector<int>>;
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::vector<M> vm(&mr);
|
||||
using P = std::pair<int, int>;
|
||||
P ar[] = {{1, 1}, {1, 2}, {1, 4}, {5, 5}};
|
||||
vm.emplace_back(
|
||||
std::sorted_equivalent, cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 4), C(3));
|
||||
assert((vm[0] == M{{1, 1}, {1, 2}, {1, 4}, {5, 5}}));
|
||||
assert(vm[0].key_comp() == C(3));
|
||||
assert(vm[0].keys().get_allocator().resource() == &mr);
|
||||
assert(vm[0].values().get_allocator().resource() == &mr);
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, initializer_list<value_type> il, const Alloc& a);
|
||||
using C = test_less<int>;
|
||||
using M = std::flat_multimap<int, int, C, std::pmr::vector<int>, std::pmr::vector<int>>;
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::vector<M> vm(&mr);
|
||||
std::pair<int, int> ar[1] = {{42, 42}};
|
||||
vm.emplace_back(std::sorted_equivalent, ar, ar, C(4));
|
||||
assert(vm[0] == M{});
|
||||
assert(vm[0].key_comp() == C(4));
|
||||
assert(vm[0].keys().get_allocator().resource() == &mr);
|
||||
assert(vm[0].values().get_allocator().resource() == &mr);
|
||||
}
|
||||
{
|
||||
// flat_multimap(InputIterator first, InputIterator last, const Alloc& a);
|
||||
// cpp_17
|
||||
using C = test_less<int>;
|
||||
using M = std::flat_multimap<int, int, C, std::pmr::vector<int>, std::pmr::vector<int>>;
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::vector<M> vm(&mr);
|
||||
using P = std::pair<int, int>;
|
||||
P ar[] = {{1, 1}, {1, 2}, {1, 4}, {5, 5}};
|
||||
vm.emplace_back(
|
||||
std::sorted_equivalent, cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 4), C(3));
|
||||
assert((vm[0] == M{{1, 1}, {1, 2}, {1, 4}, {5, 5}}));
|
||||
assert(vm[0].key_comp() == C(3));
|
||||
assert(vm[0].keys().get_allocator().resource() == &mr);
|
||||
assert(vm[0].values().get_allocator().resource() == &mr);
|
||||
}
|
||||
{
|
||||
// flat_multimap(InputIterator first, InputIterator last, const Alloc& a);
|
||||
using C = test_less<int>;
|
||||
using M = std::flat_multimap<int, int, C, std::pmr::vector<int>, std::pmr::vector<int>>;
|
||||
std::pmr::monotonic_buffer_resource mr;
|
||||
std::pmr::vector<M> vm(&mr);
|
||||
std::pair<int, int> ar[1] = {{42, 42}};
|
||||
vm.emplace_back(std::sorted_equivalent, ar, ar, C(4));
|
||||
assert(vm[0] == M{});
|
||||
assert(vm[0].key_comp() == C(4));
|
||||
assert(vm[0].keys().get_allocator().resource() == &mr);
|
||||
assert(vm[0].values().get_allocator().resource() == &mr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,227 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// template<container-compatible-range<value_type> R>
|
||||
// flat_multimap(from_range_t, R&&)
|
||||
// template<container-compatible-range<value_type> R>
|
||||
// flat_multimap(from_range_t, R&&, const key_compare&)
|
||||
// template<container-compatible-range<value_type> R, class Alloc>
|
||||
// flat_multimap(from_range_t, R&&, const Alloc&);
|
||||
// template<container-compatible-range<value_type> R, class Alloc>
|
||||
// flat_multimap(from_range_t, R&&, const key_compare&, const Alloc&);
|
||||
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "min_allocator.h"
|
||||
#include "test_allocator.h"
|
||||
#include "test_iterators.h"
|
||||
#include "test_macros.h"
|
||||
#include "../../../test_compare.h"
|
||||
|
||||
// test constraint container-compatible-range
|
||||
|
||||
template <class V>
|
||||
using RangeOf = std::ranges::subrange<V*>;
|
||||
using Map = std::flat_multimap<int, double>;
|
||||
|
||||
static_assert(std::is_constructible_v<Map, std::from_range_t, RangeOf<std::pair<int, double>>>);
|
||||
static_assert(std::is_constructible_v<Map, std::from_range_t, RangeOf<std::pair<short, double>>>);
|
||||
static_assert(!std::is_constructible_v<Map, std::from_range_t, RangeOf<int>>);
|
||||
static_assert(!std::is_constructible_v<Map, std::from_range_t, RangeOf<double>>);
|
||||
|
||||
static_assert(std::is_constructible_v<Map, std::from_range_t, RangeOf<std::pair<int, double>>, std::less<int>>);
|
||||
static_assert(std::is_constructible_v<Map, std::from_range_t, RangeOf<std::pair<short, double>>, std::less<int>>);
|
||||
static_assert(!std::is_constructible_v<Map, std::from_range_t, RangeOf<int>, std::less<int>>);
|
||||
static_assert(!std::is_constructible_v<Map, std::from_range_t, RangeOf<double>, std::less<int>>);
|
||||
|
||||
static_assert(std::is_constructible_v<Map, std::from_range_t, RangeOf<std::pair<int, double>>, std::allocator<int>>);
|
||||
static_assert(std::is_constructible_v<Map, std::from_range_t, RangeOf<std::pair<short, double>>, std::allocator<int>>);
|
||||
static_assert(!std::is_constructible_v<Map, std::from_range_t, RangeOf<int>, std::allocator<int>>);
|
||||
static_assert(!std::is_constructible_v<Map, std::from_range_t, RangeOf<double>, std::allocator<int>>);
|
||||
|
||||
static_assert(std::is_constructible_v<Map,
|
||||
std::from_range_t,
|
||||
RangeOf<std::pair<int, double>>,
|
||||
std::less<int>,
|
||||
std::allocator<int>>);
|
||||
static_assert(std::is_constructible_v<Map,
|
||||
std::from_range_t,
|
||||
RangeOf<std::pair<short, double>>,
|
||||
std::less<int>,
|
||||
std::allocator<int>>);
|
||||
static_assert(!std::is_constructible_v<Map, std::from_range_t, RangeOf<int>, std::less<int>, std::allocator<int>>);
|
||||
static_assert(!std::is_constructible_v<Map, std::from_range_t, RangeOf<double>, std::less<int>, std::allocator<int>>);
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
// The constructors in this subclause shall not participate in overload
|
||||
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
|
||||
// and uses_allocator_v<mapped_container_type, Alloc> is true.
|
||||
|
||||
using C = test_less<int>;
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = other_allocator<int>;
|
||||
using V1 = std::vector<int, A1>;
|
||||
using V2 = std::vector<int, A2>;
|
||||
using M1 = std::flat_multimap<int, int, C, V1, V1>;
|
||||
using M2 = std::flat_multimap<int, int, C, V1, V2>;
|
||||
using M3 = std::flat_multimap<int, int, C, V2, V1>;
|
||||
static_assert(std::is_constructible_v<M1, std::from_range_t, M1, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, std::from_range_t, M1, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, std::from_range_t, M2, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, std::from_range_t, M3, const A2&>);
|
||||
|
||||
static_assert(std::is_constructible_v<M1, std::from_range_t, M1, const C&, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, std::from_range_t, M1, const C&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, std::from_range_t, M2, const C&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, std::from_range_t, M3, const C&, const A2&>);
|
||||
}
|
||||
{
|
||||
// container-compatible-range
|
||||
using C = test_less<int>;
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = test_allocator<std::string>;
|
||||
using M = std::flat_multimap<int, std::string, C, std::vector<int, A1>, std::vector<std::string, A2>>;
|
||||
using Pair = std::pair<int, std::string>;
|
||||
using PairLike = std::tuple<int, std::string>;
|
||||
using NonPairLike = int;
|
||||
|
||||
static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<Pair>&>);
|
||||
static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<PairLike>&>);
|
||||
static_assert(!std::is_constructible_v<M, std::from_range_t, std::vector<NonPairLike>&>);
|
||||
|
||||
static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<Pair>&, const C&>);
|
||||
static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<PairLike>&, const C&>);
|
||||
static_assert(!std::is_constructible_v<M, std::from_range_t, std::vector<NonPairLike>&, const C&>);
|
||||
|
||||
static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<Pair>&, const A1&>);
|
||||
static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<PairLike>&, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M, std::from_range_t, std::vector<NonPairLike>&, const A1&>);
|
||||
|
||||
static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<Pair>&, const C&, const A1&>);
|
||||
static_assert(std::is_constructible_v<M, std::from_range_t, std::vector<PairLike>&, const C&, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M, std::from_range_t, std::vector<NonPairLike>&, const C&, const A1&>);
|
||||
}
|
||||
|
||||
using P = std::pair<int, short>;
|
||||
P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
|
||||
P expected[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {2, 7}, {3, 6}, {3, 8}, {3, 9}};
|
||||
{
|
||||
// flat_multimap(from_range_t, R&&)
|
||||
// input_range && !common
|
||||
using M = std::flat_multimap<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));
|
||||
|
||||
// explicit(false)
|
||||
M m2 = {std::from_range, R(Iter(ar), Sent(Iter(ar + 9)))};
|
||||
assert(m2 == m);
|
||||
}
|
||||
{
|
||||
// flat_multimap(from_range_t, R&&)
|
||||
// greater
|
||||
using M = std::flat_multimap<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, 3, 3, 2, 2, 2, 1, 1, 1}));
|
||||
LIBCPP_ASSERT((m.values() == std::deque<short>{6, 8, 9, 4, 5, 7, 1, 2, 3}));
|
||||
}
|
||||
{
|
||||
// flat_multimap(from_range_t, R&&)
|
||||
// contiguous range
|
||||
using M = std::flat_multimap<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_multimap(from_range_t, R&&, const key_compare&)
|
||||
using C = test_less<int>;
|
||||
using M = std::flat_multimap<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));
|
||||
|
||||
// explicit(false)
|
||||
M m2 = {std::from_range, R(ar, ar + 9), C(3)};
|
||||
assert(m2 == m);
|
||||
assert(m2.key_comp() == C(3));
|
||||
}
|
||||
{
|
||||
// flat_multimap(from_range_t, R&&, const Allocator&)
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = test_allocator<short>;
|
||||
using M = std::flat_multimap<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_multimap(from_range_t, R&&, const Allocator&)
|
||||
// explicit(false)
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = test_allocator<short>;
|
||||
using M = std::flat_multimap<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_multimap(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_multimap<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_multimap(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_multimap<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));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,165 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap(sorted_equivalent_t, key_container_type key_cont, mapped_container_type mapped_cont,
|
||||
// const key_compare& comp = key_compare());
|
||||
//
|
||||
// template<class Alloc>
|
||||
// flat_multimap(sorted_equivalent_t, const key_container_type& key_cont,
|
||||
// const mapped_container_type& mapped_cont, const Alloc& a);
|
||||
// template<class Alloc>
|
||||
// flat_multimap(sorted_equivalent_t, const key_container_type& key_cont,
|
||||
// const mapped_container_type& mapped_cont,
|
||||
// const key_compare& comp, const Alloc& a);
|
||||
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "min_allocator.h"
|
||||
#include "MoveOnly.h"
|
||||
#include "test_allocator.h"
|
||||
#include "test_iterators.h"
|
||||
#include "test_macros.h"
|
||||
#include "../../../test_compare.h"
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
// The constructors in this subclause shall not participate in overload
|
||||
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
|
||||
// and uses_allocator_v<mapped_container_type, Alloc> is true.
|
||||
|
||||
using C = test_less<int>;
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = other_allocator<int>;
|
||||
using V1 = std::vector<int, A1>;
|
||||
using V2 = std::vector<int, A2>;
|
||||
using M1 = std::flat_multimap<int, int, C, V1, V1>;
|
||||
using M2 = std::flat_multimap<int, int, C, V1, V2>;
|
||||
using M3 = std::flat_multimap<int, int, C, V2, V1>;
|
||||
static_assert(std::is_constructible_v<M1, std::sorted_equivalent_t, const V1&, const V1&, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, std::sorted_equivalent_t, const V1&, const V1&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, std::sorted_equivalent_t, const V1&, const V2&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, std::sorted_equivalent_t, const V2&, const V1&, const A2&>);
|
||||
|
||||
static_assert(std::is_constructible_v<M1, std::sorted_equivalent_t, const V1&, const V1&, const C&, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, std::sorted_equivalent_t, const V1&, const V1&, const C&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, std::sorted_equivalent_t, const V1&, const V2&, const C&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, std::sorted_equivalent_t, const V2&, const V1&, const C&, const A2&>);
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, key_container_type , mapped_container_type)
|
||||
using M = std::flat_multimap<int, char>;
|
||||
std::vector<int> ks = {1, 4, 4, 10};
|
||||
std::vector<char> vs = {4, 3, 2, 1};
|
||||
auto ks2 = ks;
|
||||
auto vs2 = vs;
|
||||
|
||||
auto m = M(std::sorted_equivalent, ks, vs);
|
||||
assert((m == M{{1, 4}, {4, 3}, {4, 2}, {10, 1}}));
|
||||
m = M(std::sorted_equivalent, std::move(ks), std::move(vs));
|
||||
assert(ks.empty()); // it was moved-from
|
||||
assert(vs.empty()); // it was moved-from
|
||||
assert((m == M{{1, 4}, {4, 3}, {4, 2}, {10, 1}}));
|
||||
|
||||
// explicit(false)
|
||||
M m2 = {std::sorted_equivalent, std::move(ks2), std::move(vs2)};
|
||||
assert(m == m2);
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, key_container_type , mapped_container_type)
|
||||
// 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_multimap<int, char, std::greater<int>, Ks, Vs>;
|
||||
Ks ks = {10, 1, 1, 1};
|
||||
Vs vs = {1, 2, 3, 4};
|
||||
auto m = M(std::sorted_equivalent, ks, vs);
|
||||
assert((m == M{{1, 2}, {1, 3}, {1, 4}, {10, 1}}));
|
||||
m = M(std::sorted_equivalent, std::move(ks), std::move(vs));
|
||||
assert(ks.empty()); // it was moved-from
|
||||
assert(vs.empty()); // it was moved-from
|
||||
assert((m == M{{1, 2}, {1, 3}, {1, 4}, {10, 1}}));
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, key_container_type , mapped_container_type)
|
||||
// allocator copied into the containers
|
||||
using A = test_allocator<int>;
|
||||
using M = std::flat_multimap<int, int, std::less<int>, std::vector<int, A>, std::deque<int, A>>;
|
||||
auto ks = std::vector<int, A>({2, 2, 4, 10}, A(4));
|
||||
auto vs = std::deque<int, A>({4, 3, 2, 1}, A(5));
|
||||
auto m = M(std::sorted_equivalent, std::move(ks), std::move(vs));
|
||||
assert(ks.empty()); // it was moved-from
|
||||
assert(vs.empty()); // it was moved-from
|
||||
assert((m == M{{2, 4}, {2, 3}, {4, 2}, {10, 1}}));
|
||||
assert(m.keys().get_allocator() == A(4));
|
||||
assert(m.values().get_allocator() == A(5));
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, key_container_type , mapped_container_type, key_compare)
|
||||
using C = test_less<int>;
|
||||
using M = std::flat_multimap<int, char, C>;
|
||||
std::vector<int> ks = {1, 2, 10, 10};
|
||||
std::vector<char> vs = {4, 3, 2, 1};
|
||||
|
||||
auto m = M(std::sorted_equivalent, ks, vs, C(4));
|
||||
assert((m == M{{1, 4}, {2, 3}, {10, 2}, {10, 1}}));
|
||||
assert(m.key_comp() == C(4));
|
||||
|
||||
// explicit(false)
|
||||
M m2 = {std::sorted_equivalent, ks, vs, C(4)};
|
||||
assert(m2 == m);
|
||||
assert(m2.key_comp() == C(4));
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_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_multimap<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_equivalent, 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_multimap(sorted_equivalent_t, key_container_type , mapped_container_type, const Allocator&)
|
||||
using A = test_allocator<int>;
|
||||
using M = std::flat_multimap<int, int, std::less<int>, std::vector<int, A>, std::deque<int, A>>;
|
||||
auto ks = std::vector<int, A>({1, 2, 4, 4}, A(4));
|
||||
auto vs = std::deque<int, A>({4, 3, 2, 1}, A(5));
|
||||
auto m = M(std::sorted_equivalent, 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}, {4, 1}}));
|
||||
assert(m.keys().get_allocator() == A(6));
|
||||
assert(m.values().get_allocator() == A(6));
|
||||
|
||||
// explicit(false)
|
||||
M m2 = {std::sorted_equivalent, ks, vs, A(6)};
|
||||
assert(m2 == m);
|
||||
assert(m2.keys().get_allocator() == A(6));
|
||||
assert(m2.values().get_allocator() == A(6));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,183 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// template <class InputIterator>
|
||||
// flat_multimap(sorted_equivalent_t s, initializer_list<value_type> il,
|
||||
// const key_compare& comp = key_compare())
|
||||
// template<class Alloc>
|
||||
// flat_multimap(sorted_equivalent_t, initializer_list<value_type> il, const Alloc& a);
|
||||
// template<class Alloc>
|
||||
// flat_multimap(sorted_equivalent_t, initializer_list<value_type> il,
|
||||
// const key_compare& comp, const Alloc& a);
|
||||
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "min_allocator.h"
|
||||
#include "test_allocator.h"
|
||||
#include "test_iterators.h"
|
||||
#include "test_macros.h"
|
||||
#include "../../../test_compare.h"
|
||||
|
||||
template <class T, class U>
|
||||
std::initializer_list<std::pair<T, U>> il = {{1, 1}, {4, 2}, {4, 4}, {5, 5}};
|
||||
|
||||
const auto il1 = il<int, int>;
|
||||
const auto il2 = il<int, short>;
|
||||
const auto il3 = il<short, int>;
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
// The constructors in this subclause shall not participate in overload
|
||||
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
|
||||
// and uses_allocator_v<mapped_container_type, Alloc> is true.
|
||||
using C = test_less<int>;
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = other_allocator<int>;
|
||||
using V1 = std::vector<int, A1>;
|
||||
using V2 = std::vector<int, A2>;
|
||||
using M1 = std::flat_multimap<int, int, C, V1, V1>;
|
||||
using M2 = std::flat_multimap<int, int, C, V1, V2>;
|
||||
using M3 = std::flat_multimap<int, int, C, V2, V1>;
|
||||
using IL = std::initializer_list<std::pair<int, int>>;
|
||||
static_assert(std::is_constructible_v<M1, std::sorted_equivalent_t, IL, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, std::sorted_equivalent_t, IL, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, std::sorted_equivalent_t, IL, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, std::sorted_equivalent_t, IL, const A2&>);
|
||||
|
||||
static_assert(std::is_constructible_v<M1, std::sorted_equivalent_t, IL, const C&, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, std::sorted_equivalent_t, IL, const C&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, std::sorted_equivalent_t, IL, const C&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, std::sorted_equivalent_t, IL, const C&, const A2&>);
|
||||
}
|
||||
{
|
||||
// initializer_list<value_type> needs to match exactly
|
||||
using M = std::flat_multimap<int, short>;
|
||||
using C = typename M::key_compare;
|
||||
static_assert(std::is_constructible_v<M, std::sorted_equivalent_t, std::initializer_list<std::pair<int, short>>>);
|
||||
static_assert(
|
||||
std::is_constructible_v<M, std::sorted_equivalent_t, std::initializer_list<std::pair<int, short>>, C>);
|
||||
static_assert(std::is_constructible_v<M,
|
||||
std::sorted_equivalent_t,
|
||||
std::initializer_list<std::pair<int, short>>,
|
||||
C,
|
||||
std::allocator<int>>);
|
||||
static_assert(std::is_constructible_v<M,
|
||||
std::sorted_equivalent_t,
|
||||
std::initializer_list<std::pair<int, short>>,
|
||||
std::allocator<int>>);
|
||||
static_assert(
|
||||
!std::is_constructible_v<M, std::sorted_equivalent_t, std::initializer_list<std::pair<const int, short>>>);
|
||||
static_assert(
|
||||
!std::is_constructible_v<M, std::sorted_equivalent_t, std::initializer_list<std::pair<const int, short>>, C>);
|
||||
static_assert(!std::is_constructible_v<M,
|
||||
std::sorted_equivalent_t,
|
||||
std::initializer_list<std::pair<const int, short>>,
|
||||
C,
|
||||
std::allocator<int>>);
|
||||
static_assert(!std::is_constructible_v<M,
|
||||
std::sorted_equivalent_t,
|
||||
std::initializer_list<std::pair<const int, short>>,
|
||||
std::allocator<int>>);
|
||||
static_assert(
|
||||
!std::
|
||||
is_constructible_v<M, std::sorted_equivalent_t, std::initializer_list<std::pair<const int, const short>>>);
|
||||
static_assert(!std::is_constructible_v<M,
|
||||
std::sorted_equivalent_t,
|
||||
std::initializer_list<std::pair<const int, const short>>,
|
||||
C>);
|
||||
static_assert(!std::is_constructible_v<M,
|
||||
std::sorted_equivalent_t,
|
||||
std::initializer_list<std::pair<const int, const short>>,
|
||||
C,
|
||||
std::allocator<int>>);
|
||||
static_assert(!std::is_constructible_v<M,
|
||||
std::sorted_equivalent_t,
|
||||
std::initializer_list<std::pair<const int, const short>>,
|
||||
std::allocator<int>>);
|
||||
}
|
||||
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, initializer_list<value_type>);
|
||||
using M = std::flat_multimap<int, int>;
|
||||
auto m = M(std::sorted_equivalent, il1);
|
||||
auto expected = M{{1, 1}, {4, 2}, {4, 4}, {5, 5}};
|
||||
assert(m == expected);
|
||||
|
||||
// explicit(false)
|
||||
M m2 = {std::sorted_equivalent, il1};
|
||||
assert(m2 == m);
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, initializer_list<value_type>, const key_compare&);
|
||||
using M = std::flat_multimap<int, int, std::function<bool(int, int)>>;
|
||||
auto m = M(std::sorted_equivalent, il1, std::less<int>());
|
||||
assert(m == M({{1, 1}, {4, 2}, {4, 4}, {5, 5}}, std::less<>()));
|
||||
assert(m.key_comp()(1, 2) == true);
|
||||
|
||||
// explicit(false)
|
||||
M m2 = {std::sorted_equivalent, il1, std::less<int>()};
|
||||
assert(m2 == m);
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, initializer_list<value_type>, const key_compare&);
|
||||
// greater
|
||||
using M = std::flat_multimap<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}, {1, 2}, {1, 1}};
|
||||
auto m = M(std::sorted_equivalent, il4, std::greater<int>());
|
||||
assert((m == M{{5, 5}, {4, 4}, {1, 2}, {1, 1}}));
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, initializer_list<value_type>, const Allocator&)
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = test_allocator<short>;
|
||||
using M = std::flat_multimap<int, short, std::less<int>, std::vector<int, A1>, std::deque<short, A2>>;
|
||||
auto m = M(std::sorted_equivalent, il2, A1(5));
|
||||
auto expected = M{{1, 1}, {4, 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_equivalent, il2, A1(5)};
|
||||
assert(m2 == m);
|
||||
assert(m2.keys().get_allocator() == A1(5));
|
||||
assert(m2.values().get_allocator() == A2(5));
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_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_multimap<int, short, C, std::vector<int, A1>, std::deque<short, A2>>;
|
||||
auto m = M(std::sorted_equivalent, il2, C(3), A1(5));
|
||||
assert((m == M{{1, 1}, {4, 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_multimap(sorted_equivalent_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_multimap<short, int, std::less<int>, std::deque<short, A1>, std::vector<int, A2>>;
|
||||
M m = {std::sorted_equivalent, il3, {}, A1(5)}; // implicit ctor
|
||||
assert((m == M{{1, 1}, {4, 2}, {4, 4}, {5, 5}}));
|
||||
assert(m.keys().get_allocator() == A1(5));
|
||||
assert(m.values().get_allocator() == A2(5));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,173 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// template <class InputIterator>
|
||||
// flat_multimap(sorted_equivalent_t, InputIterator first, InputIterator last, const key_compare& comp = key_compare());
|
||||
// template<class InputIterator, class Alloc>
|
||||
// flat_multimap(InputIterator first, InputIterator last, const Alloc& a);
|
||||
// template<class InputIterator, class Allocator>
|
||||
// flat_multimap(sorted_equivalent_t, InputIterator first, InputIterator last, const key_compare& comp, const Allocator& a);
|
||||
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "min_allocator.h"
|
||||
#include "test_allocator.h"
|
||||
#include "test_iterators.h"
|
||||
#include "test_macros.h"
|
||||
#include "../../../test_compare.h"
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
// The constructors in this subclause shall not participate in overload
|
||||
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
|
||||
// and uses_allocator_v<mapped_container_type, Alloc> is true.
|
||||
using C = test_less<int>;
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = other_allocator<int>;
|
||||
using V1 = std::vector<int, A1>;
|
||||
using V2 = std::vector<int, A2>;
|
||||
using M1 = std::flat_multimap<int, int, C, V1, V1>;
|
||||
using M2 = std::flat_multimap<int, int, C, V1, V2>;
|
||||
using M3 = std::flat_multimap<int, int, C, V2, V1>;
|
||||
using Iter1 = typename M1::iterator;
|
||||
using Iter2 = typename M2::iterator;
|
||||
using Iter3 = typename M3::iterator;
|
||||
static_assert(std::is_constructible_v<M1, std::sorted_equivalent_t, Iter1, Iter1, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, std::sorted_equivalent_t, Iter1, Iter1, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, std::sorted_equivalent_t, Iter2, Iter2, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, std::sorted_equivalent_t, Iter3, Iter3, const A2&>);
|
||||
|
||||
static_assert(std::is_constructible_v<M1, std::sorted_equivalent_t, Iter1, Iter1, const C&, const A1&>);
|
||||
static_assert(!std::is_constructible_v<M1, std::sorted_equivalent_t, Iter1, Iter1, const C&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M2, std::sorted_equivalent_t, Iter2, Iter2, const C&, const A2&>);
|
||||
static_assert(!std::is_constructible_v<M3, std::sorted_equivalent_t, Iter3, Iter3, const C&, const A2&>);
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, InputIterator, InputIterator);
|
||||
// cpp17_input_iterator
|
||||
using M = std::flat_multimap<int, int>;
|
||||
using P = std::pair<int, int>;
|
||||
P ar[] = {{1, 1}, {4, 4}, {5, 5}, {5, 2}};
|
||||
auto m = M(std::sorted_equivalent, cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 4));
|
||||
auto expected = M{{1, 1}, {4, 4}, {5, 5}, {5, 2}};
|
||||
assert(m == expected);
|
||||
|
||||
// explicit(false)
|
||||
M m2 = {std::sorted_equivalent, cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 4)};
|
||||
assert(m2 == m);
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, InputIterator, InputIterator);
|
||||
// contiguous iterator
|
||||
using C = test_less<int>;
|
||||
using M =
|
||||
std::flat_multimap<int, int, C, std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>;
|
||||
std::pair<int, int> ar[] = {{1, 1}, {1, 4}, {2, 2}, {5, 5}};
|
||||
auto m = M(std::sorted_equivalent, ar, ar + 4);
|
||||
auto expected = M{{1, 1}, {1, 4}, {2, 2}, {5, 5}};
|
||||
assert(m == expected);
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, InputIterator, InputIterator, const key_compare&);
|
||||
// cpp_17_input_iterator
|
||||
using M = std::flat_multimap<int, int, std::function<bool(int, int)>>;
|
||||
using P = std::pair<int, int>;
|
||||
P ar[] = {{1, 1}, {2, 2}, {2, 4}, {5, 5}};
|
||||
auto m = M(std::sorted_equivalent,
|
||||
cpp17_input_iterator<const P*>(ar),
|
||||
cpp17_input_iterator<const P*>(ar + 4),
|
||||
std::less<int>());
|
||||
assert(m == M({{1, 1}, {2, 2}, {2, 4}, {5, 5}}, std::less<>()));
|
||||
assert(m.key_comp()(1, 2) == true);
|
||||
|
||||
// explicit(false)
|
||||
M m2 = {std::sorted_equivalent,
|
||||
cpp17_input_iterator<const P*>(ar),
|
||||
cpp17_input_iterator<const P*>(ar + 4),
|
||||
std::less<int>()};
|
||||
assert(m2 == m);
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, InputIterator, InputIterator, const key_compare&);
|
||||
// greater
|
||||
using M = std::flat_multimap<int, int, std::greater<int>, std::deque<int, min_allocator<int>>, std::vector<int>>;
|
||||
using P = std::pair<int, int>;
|
||||
P ar[] = {{5, 5}, {2, 4}, {2, 2}, {1, 1}};
|
||||
auto m = M(std::sorted_equivalent,
|
||||
cpp17_input_iterator<const P*>(ar),
|
||||
cpp17_input_iterator<const P*>(ar + 4),
|
||||
std::greater<int>());
|
||||
assert((m == M{{5, 5}, {2, 4}, {2, 2}, {1, 1}}));
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, InputIterator, InputIterator, const key_compare&);
|
||||
// contiguous iterator
|
||||
using C = test_less<int>;
|
||||
using M =
|
||||
std::flat_multimap<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_equivalent, ar, ar, C(5));
|
||||
assert(m.empty());
|
||||
assert(m.key_comp() == C(5));
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, InputIterator , InputIterator, const Allocator&)
|
||||
using A1 = test_allocator<int>;
|
||||
using A2 = test_allocator<short>;
|
||||
using M = std::flat_multimap<int, short, std::less<int>, std::vector<int, A1>, std::deque<short, A2>>;
|
||||
using P = std::pair<int, int>;
|
||||
P ar[] = {{2, 1}, {2, 2}, {4, 4}, {5, 5}};
|
||||
auto m = M(std::sorted_equivalent, ar, ar + 4, A1(5));
|
||||
auto expected = M{{2, 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_equivalent, ar, ar + 4, A1(5)};
|
||||
assert(m2 == m);
|
||||
assert(m2.keys().get_allocator() == A1(5));
|
||||
assert(m2.values().get_allocator() == A2(5));
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_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_multimap<int, short, C, std::vector<int, A1>, std::deque<short, A2>>;
|
||||
using P = std::pair<int, int>;
|
||||
P ar[] = {{1, 1}, {1, 2}, {1, 4}, {1, 5}};
|
||||
auto m = M(std::sorted_equivalent, ar, ar + 4, C(3), A1(5));
|
||||
assert((m == M{{1, 1}, {1, 2}, {1, 4}, {1, 5}}));
|
||||
assert(m.key_comp() == C(3));
|
||||
assert(m.keys().get_allocator() == A1(5));
|
||||
assert(m.values().get_allocator() == A2(5));
|
||||
}
|
||||
{
|
||||
// flat_multimap(sorted_equivalent_t, InputIterator, InputIterator, const key_compare&, const Allocator&);
|
||||
// explicit(false)
|
||||
using A1 = test_allocator<short>;
|
||||
using A2 = test_allocator<int>;
|
||||
using M = std::flat_multimap<short, int, std::less<int>, std::deque<short, A1>, std::vector<int, A2>>;
|
||||
using P = std::pair<int, int>;
|
||||
P ar[] = {{1, 1}, {1, 2}, {1, 4}, {1, 5}};
|
||||
M m = {std::sorted_equivalent, ar, ar + 4, {}, A1(5)}; // implicit ctor
|
||||
assert((m == M{{1, 1}, {1, 2}, {1, 4}, {1, 5}}));
|
||||
assert(m.keys().get_allocator() == A1(5));
|
||||
assert(m.values().get_allocator() == A2(5));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// template<class Key, class T, class Compare, class KeyContainer, class MappedContainer, class Predicate>
|
||||
// typename flat_multimap<Key, T, Compare, KeyContainer, MappedContainer>::size_type
|
||||
// erase_if(flat_multimap<Key, T, Compare, KeyContainer, MappedContainer>& c, Predicate pred);
|
||||
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <vector>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "test_allocator.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
// Verify that `flat_multimap` (like `multimap`) does NOT support std::erase.
|
||||
//
|
||||
template <class S>
|
||||
concept HasStdErase = requires(S& s, typename S::value_type x) { std::erase(s, x); };
|
||||
static_assert(HasStdErase<std::vector<int>>);
|
||||
static_assert(!HasStdErase<std::flat_multimap<int, int>>);
|
||||
|
||||
template <class M>
|
||||
M make(std::initializer_list<int> vals) {
|
||||
M ret;
|
||||
for (int v : vals) {
|
||||
ret.emplace(static_cast<typename M::key_type>(v), static_cast<typename M::mapped_type>(v + 10));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
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) {
|
||||
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));
|
||||
assert(s == make<M>(expected));
|
||||
}
|
||||
|
||||
template <class S>
|
||||
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; };
|
||||
auto is3 = [](const typename S::value_type& v) { return v.first == 3; };
|
||||
auto is4 = [](auto v) { return v.first == 4; };
|
||||
auto True = [](const auto&) { return true; };
|
||||
auto False = [](auto&&) { return false; };
|
||||
|
||||
test0<S>({}, is1, {}, 0);
|
||||
|
||||
test0<S>({1}, is1, {}, 1);
|
||||
test0<S>({1, 1}, is1, {}, 2);
|
||||
test0<S>({1, 1}, is2, {1, 1}, 0);
|
||||
|
||||
test0<S>({1, 2}, is1, {2}, 1);
|
||||
test0<S>({1, 2}, is2, {1}, 1);
|
||||
test0<S>({1, 2, 2, 2}, is2, {1}, 3);
|
||||
test0<S>({1, 2, 2, 2}, is3, {1, 2, 2, 2}, 0);
|
||||
|
||||
test0<S>({1, 1, 2, 2, 3, 3}, is1, {2, 2, 3, 3}, 2);
|
||||
test0<S>({1, 1, 2, 2, 3, 3}, is2, {1, 1, 3, 3}, 2);
|
||||
test0<S>({1, 1, 2, 2, 3, 3}, is3, {1, 1, 2, 2}, 2);
|
||||
test0<S>({1, 1, 2, 2, 3, 3}, is4, {1, 1, 2, 2, 3, 3}, 0);
|
||||
|
||||
test0<S>({1, 2, 2, 3, 3, 3}, True, {}, 6);
|
||||
test0<S>({1, 2, 2, 3, 3, 3}, False, {1, 2, 2, 3, 3, 3}, 0);
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::flat_multimap<int, char>>();
|
||||
test<std::flat_multimap<int,
|
||||
char,
|
||||
std::less<int>,
|
||||
std::vector<int, min_allocator<int>>,
|
||||
std::vector<char, min_allocator<char>>>>();
|
||||
test<std::flat_multimap<int, char, std::greater<int>, std::vector<int, test_allocator<int>>>>();
|
||||
test<std::flat_multimap<int, char, std::less<int>, std::deque<int, min_allocator<int>>>>();
|
||||
test<std::flat_multimap<int, char, std::greater<int>, std::deque<int, test_allocator<int>>>>();
|
||||
test<std::flat_multimap<long, int>>();
|
||||
test<std::flat_multimap<double, int>>();
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
// UNSUPPORTED: no-exceptions
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// template<class Key, class T, class Compare, class KeyContainer, class MappedContainer, class Predicate>
|
||||
// typename flat_multimap<Key, T, Compare, KeyContainer, MappedContainer>::size_type
|
||||
// erase_if(flat_multimap<Key, T, Compare, KeyContainer, MappedContainer>& c, Predicate pred);
|
||||
// If any member function in [flat.set.defn] exits via an exception, the invariant is restored.
|
||||
// (This is not a member function, but let's respect the invariant anyway.)
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
|
||||
struct Counter {
|
||||
int c1, c2, throws;
|
||||
void tick() {
|
||||
c1 -= 1;
|
||||
if (c1 == 0) {
|
||||
c1 = c2;
|
||||
throws += 1;
|
||||
throw 42;
|
||||
}
|
||||
}
|
||||
};
|
||||
Counter g_counter = {0, 0, 0};
|
||||
|
||||
struct ThrowingAssignment {
|
||||
ThrowingAssignment(int i) : i_(i) {}
|
||||
ThrowingAssignment(const ThrowingAssignment&) = default;
|
||||
ThrowingAssignment& operator=(const ThrowingAssignment& rhs) {
|
||||
g_counter.tick();
|
||||
i_ = rhs.i_;
|
||||
g_counter.tick();
|
||||
return *this;
|
||||
}
|
||||
operator int() const { return i_; }
|
||||
int i_;
|
||||
};
|
||||
|
||||
struct ThrowingComparator {
|
||||
bool operator()(const ThrowingAssignment& a, const ThrowingAssignment& b) const {
|
||||
g_counter.tick();
|
||||
return a.i_ < b.i_;
|
||||
}
|
||||
};
|
||||
|
||||
struct ErasurePredicate {
|
||||
bool operator()(const auto& x) const { return (3 <= x.first && x.first <= 5); }
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
const std::pair<int, int> expected[] = {{1, 1}, {2, 2}, {3, 3}, {3, 3}, {5, 5}, {6, 6}, {7, 7}, {8, 8}};
|
||||
{
|
||||
using M = std::flat_multimap<ThrowingAssignment, int, ThrowingComparator>;
|
||||
for (int first_throw = 1; first_throw < 99; ++first_throw) {
|
||||
for (int second_throw = 1; second_throw < 99; ++second_throw) {
|
||||
g_counter = {0, 0, 0};
|
||||
M m = M({1, 2, 3, 3, 5, 6, 7, 8}, {1, 2, 3, 3, 5, 6, 7, 8});
|
||||
try {
|
||||
g_counter = {first_throw, second_throw, 0};
|
||||
auto n = std::erase_if(m, ErasurePredicate());
|
||||
assert(n == 3);
|
||||
// If it didn't throw at all, we're done.
|
||||
g_counter = {0, 0, 0};
|
||||
assert((m == M{{1, 1}, {2, 2}, {6, 6}, {7, 7}, {8, 8}}));
|
||||
first_throw = 99; // "done"
|
||||
break;
|
||||
} catch (int ex) {
|
||||
assert(ex == 42);
|
||||
check_invariant(m);
|
||||
LIBCPP_ASSERT(m.empty() || std::equal(m.begin(), m.end(), expected, expected + 8));
|
||||
if (g_counter.throws == 1) {
|
||||
// We reached the first throw but not the second throw.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
using M = std::flat_multimap<int, ThrowingAssignment, ThrowingComparator>;
|
||||
for (int first_throw = 1; first_throw < 99; ++first_throw) {
|
||||
for (int second_throw = 1; second_throw < 99; ++second_throw) {
|
||||
g_counter = {0, 0, 0};
|
||||
M m = M({1, 2, 3, 3, 5, 6, 7, 8}, {1, 2, 3, 3, 5, 6, 7, 8});
|
||||
try {
|
||||
g_counter = {first_throw, second_throw, 0};
|
||||
auto n = std::erase_if(m, ErasurePredicate());
|
||||
assert(n == 3);
|
||||
// If it didn't throw at all, we're done.
|
||||
g_counter = {0, 0, 0};
|
||||
assert((m == M{{1, 1}, {2, 2}, {6, 6}, {7, 7}, {8, 8}}));
|
||||
first_throw = 99; // "done"
|
||||
break;
|
||||
} catch (int ex) {
|
||||
assert(ex == 42);
|
||||
check_invariant(m);
|
||||
LIBCPP_ASSERT(m.empty() || std::equal(m.begin(), m.end(), expected, expected + 8));
|
||||
if (g_counter.throws == 1) {
|
||||
// We reached the first throw but not the second throw.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
using M = std::
|
||||
flat_multimap<ThrowingAssignment, int, ThrowingComparator, std::deque<ThrowingAssignment>, std::deque<int>>;
|
||||
for (int first_throw = 1; first_throw < 99; ++first_throw) {
|
||||
for (int second_throw = 1; second_throw < 99; ++second_throw) {
|
||||
g_counter = {0, 0, 0};
|
||||
std::deque<ThrowingAssignment> container = {5, 6, 7, 8};
|
||||
container.insert(container.begin(), {1, 2, 3, 3});
|
||||
M m = M(std::move(container), {1, 2, 3, 3, 5, 6, 7, 8});
|
||||
try {
|
||||
g_counter = {first_throw, second_throw, 0};
|
||||
auto n = std::erase_if(m, ErasurePredicate());
|
||||
assert(n == 3);
|
||||
// If it didn't throw at all, we're done.
|
||||
g_counter = {0, 0, 0};
|
||||
assert((m == M{{1, 1}, {2, 2}, {6, 6}, {7, 7}, {8, 8}}));
|
||||
first_throw = 99; // "done"
|
||||
break;
|
||||
} catch (int ex) {
|
||||
assert(ex == 42);
|
||||
check_invariant(m);
|
||||
LIBCPP_ASSERT(m.empty() || std::equal(m.begin(), m.end(), expected, expected + 8));
|
||||
if (g_counter.throws == 1) {
|
||||
// We reached the first throw but not the second throw.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// iterator begin() noexcept;
|
||||
// const_iterator begin() const noexcept
|
||||
// iterator end() noexcept;
|
||||
// const_iterator end() const noexcept;
|
||||
//
|
||||
// const_iterator cbegin() const noexcept;
|
||||
// const_iterator cend() const noexcept;
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
|
||||
M m = {{1, 'a'}, {1, 'z'}, {2, 'b'}, {3, 'a'}, {3, 'b'}, {3, 'c'}, {4, 'd'}};
|
||||
const M& cm = m;
|
||||
ASSERT_SAME_TYPE(decltype(m.begin()), typename M::iterator);
|
||||
ASSERT_SAME_TYPE(decltype(m.cbegin()), typename M::const_iterator);
|
||||
ASSERT_SAME_TYPE(decltype(cm.begin()), typename M::const_iterator);
|
||||
ASSERT_SAME_TYPE(decltype(m.end()), typename M::iterator);
|
||||
ASSERT_SAME_TYPE(decltype(m.cend()), typename M::const_iterator);
|
||||
ASSERT_SAME_TYPE(decltype(cm.end()), typename M::const_iterator);
|
||||
static_assert(noexcept(m.begin()));
|
||||
static_assert(noexcept(cm.begin()));
|
||||
static_assert(noexcept(m.cbegin()));
|
||||
static_assert(noexcept(m.end()));
|
||||
static_assert(noexcept(cm.end()));
|
||||
static_assert(noexcept(m.cend()));
|
||||
assert(m.size() == 7);
|
||||
assert(std::distance(m.begin(), m.end()) == 7);
|
||||
assert(std::distance(cm.begin(), cm.end()) == 7);
|
||||
assert(std::distance(m.cbegin(), m.cend()) == 7);
|
||||
typename M::iterator i; // default-construct
|
||||
i = m.begin(); // move-assignment
|
||||
typename M::const_iterator k = i; // converting constructor
|
||||
assert(i == k); // comparison
|
||||
assert(i->first == 1); // operator->
|
||||
assert(i->second == 'a'); // operator->
|
||||
++i; // pre-increment
|
||||
assert(i->first == 1); // operator->
|
||||
assert(i->second == 'z'); // operator->
|
||||
i = i + 3; // operator+
|
||||
assert((*i).first == 3); // operator*
|
||||
assert((*i).second == 'b'); // operator*
|
||||
i += 3; // operator+=
|
||||
assert(i == m.end()); // operator==
|
||||
--i; // pre-decrement
|
||||
assert(i->first == 4); // operator->
|
||||
assert(i->second == 'd'); // operator->
|
||||
i = i - 2; // operator-
|
||||
assert(i->first == 3); // operator->
|
||||
assert(i->second == 'b'); // operator->
|
||||
i -= 2; // operator-=
|
||||
assert(i > m.begin()); // operator>
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<int>, std::vector<char>>();
|
||||
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_multimap<int, char>;
|
||||
C::iterator ii1{}, ii2{};
|
||||
C::iterator ii4 = ii1;
|
||||
C::const_iterator cii{};
|
||||
assert(ii1 == ii2);
|
||||
assert(ii1 == ii4);
|
||||
assert(!(ii1 != ii2));
|
||||
|
||||
assert((ii1 == cii));
|
||||
assert((cii == ii1));
|
||||
assert(!(ii1 != cii));
|
||||
assert(!(cii != ii1));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// flat_multimap iterators should be C++20 random access iterators
|
||||
|
||||
#include <compare>
|
||||
#include <concepts>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
using KI = typename KeyContainer::iterator;
|
||||
using I = M::iterator;
|
||||
using CI = M::const_iterator;
|
||||
using RI = M::reverse_iterator;
|
||||
using CRI = M::const_reverse_iterator;
|
||||
|
||||
static_assert(std::equality_comparable<I>);
|
||||
static_assert(std::equality_comparable<CI>);
|
||||
static_assert(std::equality_comparable<RI>);
|
||||
static_assert(std::equality_comparable<CRI>);
|
||||
|
||||
static_assert(std::totally_ordered<I>);
|
||||
static_assert(std::totally_ordered<CI>);
|
||||
static_assert(std::totally_ordered<RI>);
|
||||
static_assert(std::totally_ordered<CRI>);
|
||||
|
||||
M m = {{1, 'a'}, {2, 'b'}, {2, 'e'}, {3, 'z'}, {3, 'y'}, {3, 'c'}, {4, 'd'}};
|
||||
|
||||
I i1 = m.begin();
|
||||
I i2 = m.begin() + 1;
|
||||
|
||||
assert(i1 == i1);
|
||||
assert(!(i1 != i1));
|
||||
assert(i1 != i2);
|
||||
assert(!(i1 == i2));
|
||||
assert(i1 < i2);
|
||||
assert(!(i1 < i1));
|
||||
assert(i1 <= i1);
|
||||
assert(i1 <= i2);
|
||||
assert(!(i2 <= i1));
|
||||
assert(i2 > i1);
|
||||
assert(!(i2 > i2));
|
||||
assert(i2 >= i1);
|
||||
assert(i2 >= i2);
|
||||
assert(!(i1 >= i2));
|
||||
|
||||
CI ci1 = m.cbegin();
|
||||
CI ci2 = m.cbegin() + 1;
|
||||
assert(ci1 == ci1);
|
||||
assert(!(ci1 != ci1));
|
||||
assert(ci1 != ci2);
|
||||
assert(!(ci1 == ci2));
|
||||
assert(ci1 < ci2);
|
||||
assert(!(ci1 < ci1));
|
||||
assert(ci1 <= ci1);
|
||||
assert(ci1 <= ci2);
|
||||
assert(!(ci2 <= ci1));
|
||||
assert(ci2 > ci1);
|
||||
assert(!(ci2 > ci2));
|
||||
assert(ci2 >= ci1);
|
||||
assert(ci2 >= ci2);
|
||||
assert(!(ci1 >= ci2));
|
||||
|
||||
RI ri1 = m.rbegin();
|
||||
RI ri2 = m.rbegin() + 1;
|
||||
assert(ri1 == ri1);
|
||||
assert(!(ri1 != ri1));
|
||||
assert(ri1 != ri2);
|
||||
assert(!(ri1 == ri2));
|
||||
assert(ri1 < ri2);
|
||||
assert(!(ri1 < ri1));
|
||||
assert(ri1 <= ri1);
|
||||
assert(ri1 <= ri2);
|
||||
assert(!(ri2 <= ri1));
|
||||
assert(ri2 > ri1);
|
||||
assert(!(ri2 > ri2));
|
||||
assert(ri2 >= ri1);
|
||||
assert(ri2 >= ri2);
|
||||
assert(!(ri1 >= ri2));
|
||||
|
||||
CRI cri1 = m.crbegin();
|
||||
CRI cri2 = m.crbegin() + 1;
|
||||
assert(cri1 == cri1);
|
||||
assert(!(cri1 != cri1));
|
||||
assert(cri1 != cri2);
|
||||
assert(!(cri1 == cri2));
|
||||
assert(cri1 < cri2);
|
||||
assert(!(cri1 < cri1));
|
||||
assert(cri1 <= cri1);
|
||||
assert(cri1 <= cri2);
|
||||
assert(!(cri2 <= cri1));
|
||||
assert(cri2 > cri1);
|
||||
assert(!(cri2 > cri2));
|
||||
assert(cri2 >= cri1);
|
||||
assert(cri2 >= cri2);
|
||||
assert(!(cri1 >= cri2));
|
||||
|
||||
if constexpr (std::three_way_comparable<KI>) {
|
||||
static_assert(std::three_way_comparable<I>); // ...of course the wrapped iterators still support <=>.
|
||||
static_assert(std::three_way_comparable<CI>);
|
||||
static_assert(std::three_way_comparable<RI>);
|
||||
static_assert(std::three_way_comparable<CRI>);
|
||||
static_assert(std::same_as<decltype(I() <=> I()), std::strong_ordering>);
|
||||
static_assert(std::same_as<decltype(I() <=> CI()), std::strong_ordering>);
|
||||
static_assert(std::same_as<decltype(CI() <=> CI()), std::strong_ordering>);
|
||||
static_assert(std::same_as<decltype(RI() <=> RI()), std::strong_ordering>);
|
||||
static_assert(std::same_as<decltype(RI() <=> CRI()), std::strong_ordering>);
|
||||
static_assert(std::same_as<decltype(CRI() <=> CRI()), std::strong_ordering>);
|
||||
|
||||
assert(i1 <=> i1 == std::strong_ordering::equivalent);
|
||||
assert(i1 <=> i2 == std::strong_ordering::less);
|
||||
assert(i2 <=> i1 == std::strong_ordering::greater);
|
||||
|
||||
assert(ci1 <=> ci1 == std::strong_ordering::equivalent);
|
||||
assert(ci1 <=> ci2 == std::strong_ordering::less);
|
||||
assert(ci2 <=> ci1 == std::strong_ordering::greater);
|
||||
|
||||
assert(ri1 <=> ri1 == std::strong_ordering::equivalent);
|
||||
assert(ri1 <=> ri2 == std::strong_ordering::less);
|
||||
assert(ri2 <=> ri1 == std::strong_ordering::greater);
|
||||
|
||||
assert(cri1 <=> cri1 == std::strong_ordering::equivalent);
|
||||
assert(cri1 <=> cri2 == std::strong_ordering::less);
|
||||
assert(cri2 <=> cri1 == std::strong_ordering::greater);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<int>, std::vector<char>>();
|
||||
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 0;
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// iterator, const_iterator, reverse_iterator, const_reverse_iterator
|
||||
|
||||
#include <flat_map>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <type_traits>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using C = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
using I = C::iterator;
|
||||
using CI = C::const_iterator;
|
||||
using RI = C::reverse_iterator;
|
||||
using CRI = C::const_reverse_iterator;
|
||||
static_assert(std::random_access_iterator<I>);
|
||||
static_assert(std::random_access_iterator<CI>);
|
||||
static_assert(std::random_access_iterator<RI>);
|
||||
static_assert(std::random_access_iterator<CRI>);
|
||||
static_assert(!std::contiguous_iterator<I>);
|
||||
static_assert(!std::contiguous_iterator<CI>);
|
||||
static_assert(!std::contiguous_iterator<RI>);
|
||||
static_assert(!std::contiguous_iterator<CRI>);
|
||||
static_assert(!std::indirectly_writable<I, std::pair<int, char>>);
|
||||
static_assert(!std::indirectly_writable<CI, std::pair<int, char>>);
|
||||
static_assert(!std::indirectly_writable<RI, std::pair<int, char>>);
|
||||
static_assert(!std::indirectly_writable<CRI, std::pair<int, char>>);
|
||||
static_assert(std::sentinel_for<I, I>);
|
||||
static_assert(std::sentinel_for<I, CI>);
|
||||
static_assert(!std::sentinel_for<I, RI>);
|
||||
static_assert(!std::sentinel_for<I, CRI>);
|
||||
static_assert(std::sentinel_for<CI, I>);
|
||||
static_assert(std::sentinel_for<CI, CI>);
|
||||
static_assert(!std::sentinel_for<CI, RI>);
|
||||
static_assert(!std::sentinel_for<CI, CRI>);
|
||||
static_assert(!std::sentinel_for<RI, I>);
|
||||
static_assert(!std::sentinel_for<RI, CI>);
|
||||
static_assert(std::sentinel_for<RI, RI>);
|
||||
static_assert(std::sentinel_for<RI, CRI>);
|
||||
static_assert(!std::sentinel_for<CRI, I>);
|
||||
static_assert(!std::sentinel_for<CRI, CI>);
|
||||
static_assert(std::sentinel_for<CRI, RI>);
|
||||
static_assert(std::sentinel_for<CRI, CRI>);
|
||||
static_assert(std::indirectly_movable_storable<I, std::pair<int, char>*>);
|
||||
static_assert(std::indirectly_movable_storable<CI, std::pair<int, char>*>);
|
||||
static_assert(std::indirectly_movable_storable<RI, std::pair<int, char>*>);
|
||||
static_assert(std::indirectly_movable_storable<CRI, std::pair<int, char>*>);
|
||||
|
||||
#ifdef _LIBCPP_VERSION
|
||||
static_assert(std::is_same_v<typename std::iterator_traits<I>::iterator_category, std::random_access_iterator_tag>);
|
||||
static_assert(std::is_same_v<typename std::iterator_traits<CI>::iterator_category, std::random_access_iterator_tag>);
|
||||
static_assert(std::is_same_v<typename std::iterator_traits<RI>::iterator_category, std::random_access_iterator_tag>);
|
||||
static_assert(std::is_same_v<typename std::iterator_traits<CRI>::iterator_category, std::random_access_iterator_tag>);
|
||||
#endif
|
||||
}
|
||||
|
||||
void test() {
|
||||
test<std::vector<int>, std::vector<char>>();
|
||||
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>>>();
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
#include <concepts>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <ranges>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
{
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using C = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
|
||||
static_assert(std::same_as<std::ranges::iterator_t<C>, typename C::iterator>);
|
||||
static_assert(std::ranges::random_access_range<C>);
|
||||
static_assert(!std::ranges::contiguous_range<C>);
|
||||
static_assert(std::ranges::common_range<C>);
|
||||
static_assert(std::ranges::input_range<C>);
|
||||
static_assert(!std::ranges::view<C>);
|
||||
static_assert(std::ranges::sized_range<C>);
|
||||
static_assert(!std::ranges::borrowed_range<C>);
|
||||
static_assert(std::ranges::viewable_range<C>);
|
||||
|
||||
static_assert(std::same_as<std::ranges::iterator_t<const C>, typename C::const_iterator>);
|
||||
static_assert(std::ranges::random_access_range<const C>);
|
||||
static_assert(!std::ranges::contiguous_range<const C>);
|
||||
static_assert(std::ranges::common_range<const C>);
|
||||
static_assert(std::ranges::input_range<const C>);
|
||||
static_assert(!std::ranges::view<const C>);
|
||||
static_assert(std::ranges::sized_range<const C>);
|
||||
static_assert(!std::ranges::borrowed_range<const C>);
|
||||
static_assert(!std::ranges::viewable_range<const C>);
|
||||
}
|
||||
}
|
||||
|
||||
void test() {
|
||||
test<std::vector<int>, std::vector<char>>();
|
||||
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>>>();
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// reverse_iterator rbegin() noexcept;
|
||||
// const_reverse_iterator rbegin() const noexcept;
|
||||
// reverse_iterator rend() noexcept;
|
||||
// const_reverse_iterator rend() const noexcept;
|
||||
//
|
||||
// const_reverse_iterator crbegin() const noexcept;
|
||||
// const_reverse_iterator crend() const noexcept;
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include <iostream>
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
using M = std::flat_multimap<int, char, std::less<int>, std::deque<int>, std::deque<char>>;
|
||||
M m = {{1, 'a'}, {1, 'b'}, {2, 'c'}, {2, 'd'}, {3, 'e'}, {3, 'f'}, {4, 'g'}, {4, 'h'}};
|
||||
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() == 8);
|
||||
assert(std::distance(m.rbegin(), m.rend()) == 8);
|
||||
assert(std::distance(cm.rbegin(), cm.rend()) == 8);
|
||||
assert(std::distance(m.crbegin(), m.crend()) == 8);
|
||||
assert(std::distance(cm.crbegin(), cm.crend()) == 8);
|
||||
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 = 8; j >= 1; --j, ++i) { // pre-increment
|
||||
assert(i->first == (j + 1) / 2); // operator->
|
||||
assert(i->second == 'a' + j - 1);
|
||||
}
|
||||
assert(i == m.rend());
|
||||
for (int j = 1; j <= 8; ++j) {
|
||||
--i; // pre-decrement
|
||||
assert((*i).first == (j + 1) / 2);
|
||||
assert((*i).second == 'a' + j - 1);
|
||||
}
|
||||
assert(i == m.rbegin());
|
||||
}
|
||||
{
|
||||
// N3644 testing
|
||||
using C = std::flat_multimap<int, char>;
|
||||
C::reverse_iterator ii1{}, ii2{};
|
||||
C::reverse_iterator ii4 = ii1;
|
||||
C::const_reverse_iterator cii{};
|
||||
assert(ii1 == ii2);
|
||||
assert(ii1 == ii4);
|
||||
assert(!(ii1 != ii2));
|
||||
|
||||
assert((ii1 == cii));
|
||||
assert((cii == ii1));
|
||||
assert(!(ii1 != cii));
|
||||
assert(!(cii != ii1));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// void clear() noexcept;
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
// test noexcept
|
||||
|
||||
template <class T>
|
||||
concept NoExceptClear = requires(T t) {
|
||||
{ t.clear() } noexcept;
|
||||
};
|
||||
|
||||
static_assert(NoExceptClear<std::flat_multimap<int, int>>);
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
static_assert(
|
||||
NoExceptClear<std::flat_multimap<int, int, std::less<int>, ThrowOnMoveContainer<int>, ThrowOnMoveContainer<int>>>);
|
||||
#endif
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
|
||||
M m = {{5, 2}, {2, 1}, {2, 3}, {2, 1}, {5, 0}};
|
||||
assert(m.size() == 5);
|
||||
ASSERT_NOEXCEPT(m.clear());
|
||||
ASSERT_SAME_TYPE(decltype(m.clear()), void);
|
||||
m.clear();
|
||||
assert(m.size() == 0);
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<int>, std::vector<int>>();
|
||||
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<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,158 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// template <class... Args>
|
||||
// iterator emplace(Args&&... args);
|
||||
|
||||
#include <flat_map>
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <tuple>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "../../../Emplaceable.h"
|
||||
#include "DefaultOnly.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
// Constraints: is_constructible_v<pair<key_type, mapped_type>, Args...> is true.
|
||||
template <class M, class... Args>
|
||||
concept CanEmplace = requires(M m, Args&&... args) { m.emplace(std::forward<Args>(args)...); };
|
||||
|
||||
using Map = std::flat_multimap<Emplaceable, Emplaceable>;
|
||||
static_assert(CanEmplace<Map>);
|
||||
static_assert(CanEmplace<Map, Emplaceable, Emplaceable>);
|
||||
static_assert(CanEmplace<Map, std::piecewise_construct_t, std::tuple<int, double>, std::tuple<int, double>>);
|
||||
static_assert(!CanEmplace<Map, Emplaceable>);
|
||||
static_assert(!CanEmplace<Map, int, double>);
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
using R = typename M::iterator;
|
||||
|
||||
{
|
||||
// was empty
|
||||
M m;
|
||||
std::same_as<R> decltype(auto) r = m.emplace(typename M::value_type(2, 3.5));
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 1);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 3.5);
|
||||
}
|
||||
{
|
||||
// key does not exist and inserted at the begin
|
||||
M m = {{3, 4.0}, {3, 3.0}, {3, 1.0}, {7, 0.0}};
|
||||
std::same_as<R> decltype(auto) r = m.emplace(typename M::value_type(2, 2.0));
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 5);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
}
|
||||
{
|
||||
// key does not exist and inserted in the middle
|
||||
M m = {{1, 4.0}, {1, 3.0}, {3, 1.0}, {4, 0.0}};
|
||||
std::same_as<R> decltype(auto) r = m.emplace(typename M::value_type(2, 2.0));
|
||||
assert(r == m.begin() + 2);
|
||||
assert(m.size() == 5);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
}
|
||||
{
|
||||
// key does not exist and inserted at the end
|
||||
M m = {{1, 4.0}, {1, 3.0}};
|
||||
std::same_as<R> decltype(auto) r = m.emplace(typename M::value_type(2, 2.0));
|
||||
assert(r == m.begin() + 2);
|
||||
assert(m.size() == 3);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
}
|
||||
{
|
||||
// key already exists and original at the begin
|
||||
M m = {{2, 4.0}, {2, 3.0}, {5, 1.0}, {6, 0.0}};
|
||||
std::same_as<R> decltype(auto) r = m.emplace(typename M::value_type(2, 2.0));
|
||||
assert(r == m.begin() + 2);
|
||||
assert(m.size() == 5);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
}
|
||||
{
|
||||
// key already exists and original in the middle
|
||||
M m = {{0, 4.0}, {2, 3.0}, {2, 1.0}, {4, 0.0}};
|
||||
std::same_as<R> decltype(auto) r = m.emplace(typename M::value_type(2, 2.0));
|
||||
assert(r == m.begin() + 3);
|
||||
assert(m.size() == 5);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
}
|
||||
{
|
||||
// key already exists and original at the end
|
||||
M m = {{0, 4.0}, {1, 3.0}, {2, 1.0}};
|
||||
std::same_as<R> decltype(auto) r = m.emplace(typename M::value_type(2, 2.0));
|
||||
assert(r == m.begin() + 3);
|
||||
assert(m.size() == 4);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
}
|
||||
}
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test_emplaceable() {
|
||||
using M = std::flat_multimap<int, Emplaceable, std::less<int>, KeyContainer, ValueContainer>;
|
||||
using R = typename M::iterator;
|
||||
|
||||
M m;
|
||||
std::same_as<R> decltype(auto) r =
|
||||
m.emplace(std::piecewise_construct, std::forward_as_tuple(2), std::forward_as_tuple());
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 1);
|
||||
assert(m.begin()->first == 2);
|
||||
assert(m.begin()->second == Emplaceable());
|
||||
r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(2, 3.5));
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 2);
|
||||
assert(m.begin()->first == 1);
|
||||
assert(m.begin()->second == Emplaceable(2, 3.5));
|
||||
r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(2, 3.5));
|
||||
assert(r == m.begin() + 1);
|
||||
assert(m.size() == 3);
|
||||
assert(m.begin()->first == 1);
|
||||
assert(m.begin()->second == Emplaceable(2, 3.5));
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
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>>>();
|
||||
|
||||
{
|
||||
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 0;
|
||||
}
|
@ -0,0 +1,228 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// template <class... Args>
|
||||
// iterator emplace_hint(const_iterator position, Args&&... args);
|
||||
|
||||
#include <flat_map>
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_macros.h"
|
||||
#include "../../../Emplaceable.h"
|
||||
#include "DefaultOnly.h"
|
||||
#include "min_allocator.h"
|
||||
#include "../helpers.h"
|
||||
|
||||
#if defined(_LIBCPP_VERSION)
|
||||
// spec only specifies `emplace(Args&&...)` is_constructible_v<pair<key_type, mapped_type>, Args...> is true.
|
||||
// nothing mentioned for emplace_hint
|
||||
template <class M, class... Args>
|
||||
concept CanEmplaceHint =
|
||||
requires(M m, typename M::const_iterator i, Args&&... args) { m.emplace_hint(i, std::forward<Args>(args)...); };
|
||||
|
||||
using Map = std::flat_multimap<Emplaceable, Emplaceable>;
|
||||
static_assert(CanEmplaceHint<Map>);
|
||||
static_assert(CanEmplaceHint<Map, Emplaceable, Emplaceable>);
|
||||
static_assert(CanEmplaceHint<Map, std::piecewise_construct_t, std::tuple<int, double>, std::tuple<int, double>>);
|
||||
static_assert(!CanEmplaceHint<Map, Emplaceable>);
|
||||
static_assert(!CanEmplaceHint<Map, int, double>);
|
||||
#endif
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
using R = M::iterator;
|
||||
{
|
||||
// was empty
|
||||
M m;
|
||||
std::same_as<R> decltype(auto) r = m.emplace_hint(m.end(), typename M::value_type(2, 3.5));
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 1);
|
||||
assert(m.begin()->first == 2);
|
||||
assert(m.begin()->second == 3.5);
|
||||
}
|
||||
{
|
||||
// hint correct and no duplicates
|
||||
M m = {{0, 0.0}, {1, 1.0}, {3, 3.0}};
|
||||
auto it = m.begin() + 2;
|
||||
std::same_as<R> decltype(auto) r = m.emplace_hint(it, typename M::value_type(2, 2.0));
|
||||
assert(r == m.begin() + 2);
|
||||
assert(m.size() == 4);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
}
|
||||
{
|
||||
// hint correct and at the begin
|
||||
M m = {{3, 3.0}, {4, 4.0}};
|
||||
auto it = m.begin();
|
||||
std::same_as<R> decltype(auto) r = m.emplace_hint(it, typename M::value_type(2, 2.0));
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 3);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
}
|
||||
{
|
||||
// hint correct and at the end
|
||||
M m = {{0, 0.0}, {1, 1.0}};
|
||||
auto it = m.end();
|
||||
std::same_as<R> decltype(auto) r = m.emplace_hint(it, typename M::value_type(2, 2.0));
|
||||
assert(r == m.begin() + 2);
|
||||
assert(m.size() == 3);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
}
|
||||
{
|
||||
// hint correct and at first duplicate
|
||||
M m = {{0, 0.0}, {1, 1.0}, {2, 1.9}, {2, 2.1}, {3, 3.0}};
|
||||
auto it = m.begin() + 2;
|
||||
std::same_as<R> decltype(auto) r = m.emplace_hint(it, typename M::value_type(2, 2.0));
|
||||
assert(r == m.begin() + 2);
|
||||
assert(m.size() == 6);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
assert(std::next(r)->first == 2);
|
||||
assert(std::next(r)->second == 1.9);
|
||||
}
|
||||
{
|
||||
// hint correct and in-between duplicates
|
||||
M m = {{0, 0.0}, {1, 1.0}, {2, 1.8}, {2, 1.9}, {2, 2.1}, {3, 3.0}};
|
||||
auto it = m.begin() + 4;
|
||||
std::same_as<R> decltype(auto) r = m.emplace_hint(it, typename M::value_type(2, 2.0));
|
||||
assert(r == m.begin() + 4);
|
||||
assert(m.size() == 7);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
assert(std::next(r)->first == 2);
|
||||
assert(std::next(r)->second == 2.1);
|
||||
}
|
||||
{
|
||||
// hint correct and after duplicates
|
||||
M m = {{0, 0.0}, {1, 1.0}, {2, 1.8}, {2, 1.9}, {2, 2.1}, {3, 3.0}};
|
||||
auto it = m.begin() + 5;
|
||||
std::same_as<R> decltype(auto) r = m.emplace_hint(it, typename M::value_type(2, 2.0));
|
||||
assert(r == m.begin() + 5);
|
||||
assert(m.size() == 7);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
assert(std::next(r)->first == 3);
|
||||
assert(std::next(r)->second == 3.0);
|
||||
}
|
||||
{
|
||||
// hint incorrect and no duplicates
|
||||
M m = {{0, 0.0}, {1, 1.0}, {3, 3.0}};
|
||||
auto it = m.begin() + 1;
|
||||
std::same_as<R> decltype(auto) r = m.emplace_hint(it, typename M::value_type(2, 2.0));
|
||||
assert(r == m.begin() + 2);
|
||||
assert(m.size() == 4);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
}
|
||||
{
|
||||
// hint incorrect and at the begin
|
||||
M m = {{0, 0.0}, {1, 1.0}};
|
||||
auto it = m.begin();
|
||||
std::same_as<R> decltype(auto) r = m.emplace_hint(it, typename M::value_type(2, 2.0));
|
||||
assert(r == m.begin() + 2);
|
||||
assert(m.size() == 3);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
}
|
||||
{
|
||||
// hint incorrect and at the end
|
||||
M m = {{3, 3.0}, {4, 4.0}};
|
||||
auto it = m.end();
|
||||
std::same_as<R> decltype(auto) r = m.emplace_hint(it, typename M::value_type(2, 2.0));
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 3);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
}
|
||||
{
|
||||
// hint incorrect and before the first duplicate
|
||||
M m = {{0, 0.0}, {1, 1.0}, {2, 1.8}, {2, 1.9}, {2, 2.1}, {3, 3.0}};
|
||||
auto it = m.begin();
|
||||
std::same_as<R> decltype(auto) r = m.emplace_hint(it, typename M::value_type(2, 2.0));
|
||||
// the result is as left as possible
|
||||
assert(r == m.begin() + 2);
|
||||
assert(m.size() == 7);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
assert(std::next(r)->first == 2);
|
||||
assert(std::next(r)->second == 1.8);
|
||||
}
|
||||
{
|
||||
// hint incorrect and after the last duplicate
|
||||
M m = {{0, 0.0}, {1, 1.0}, {2, 1.8}, {2, 1.9}, {2, 2.1}, {3, 3.0}, {4, 4.0}};
|
||||
auto it = m.begin() + 6;
|
||||
std::same_as<R> decltype(auto) r = m.emplace_hint(it, typename M::value_type(2, 2.0));
|
||||
// the result is as right as possible
|
||||
assert(r == m.begin() + 5);
|
||||
assert(m.size() == 8);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.0);
|
||||
assert(std::next(r)->first == 3);
|
||||
assert(std::next(r)->second == 3.0);
|
||||
}
|
||||
}
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test_emplaceable() {
|
||||
using M = std::flat_multimap<int, Emplaceable, std::less<int>, KeyContainer, ValueContainer>;
|
||||
using R = M::iterator;
|
||||
|
||||
M m;
|
||||
ASSERT_SAME_TYPE(decltype(m.emplace_hint(m.cbegin())), R);
|
||||
R r = m.emplace_hint(m.end(), std::piecewise_construct, std::forward_as_tuple(2), std::forward_as_tuple());
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 1);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == Emplaceable());
|
||||
r = m.emplace_hint(m.end(), std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(2, 3.5));
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 2);
|
||||
assert(r->first == 1);
|
||||
assert(r->second == Emplaceable(2, 3.5));
|
||||
r = m.emplace_hint(m.end(), std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(2, 3.6));
|
||||
assert(r == m.begin() + 1);
|
||||
assert(m.size() == 3);
|
||||
assert(r->first == 1);
|
||||
assert(r->second == Emplaceable(2, 3.6));
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
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>>>();
|
||||
|
||||
{
|
||||
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 0;
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// iterator erase(iterator position);
|
||||
// iterator erase(const_iterator position);
|
||||
|
||||
#include <compare>
|
||||
#include <concepts>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
using P = std::pair<Key, Value>;
|
||||
using I = M::iterator;
|
||||
|
||||
P ar[] = {
|
||||
P(1, 1.5),
|
||||
P(2, 2.5),
|
||||
P(2, 2.6),
|
||||
P(3, 3.5),
|
||||
P(4, 4.5),
|
||||
P(4, 4.5),
|
||||
P(4, 4.7),
|
||||
P(5, 5.5),
|
||||
P(6, 6.5),
|
||||
P(7, 7.5),
|
||||
P(8, 8.5),
|
||||
};
|
||||
M m(ar, ar + sizeof(ar) / sizeof(ar[0]));
|
||||
assert(m.size() == 11);
|
||||
std::same_as<I> decltype(auto) i1 = m.erase(std::next(m.cbegin(), 2));
|
||||
assert(m.size() == 10);
|
||||
assert(i1 == std::next(m.begin(), 2));
|
||||
assert(std::ranges::equal(
|
||||
m,
|
||||
std::vector<P>{
|
||||
{1, 1.5}, {2, 2.5}, {3, 3.5}, {4, 4.5}, {4, 4.5}, {4, 4.7}, {5, 5.5}, {6, 6.5}, {7, 7.5}, {8, 8.5}}));
|
||||
|
||||
std::same_as<I> decltype(auto) i2 = m.erase(std::next(m.begin(), 0));
|
||||
assert(m.size() == 9);
|
||||
assert(i2 == m.begin());
|
||||
assert(std::ranges::equal(
|
||||
m, std::vector<P>{{2, 2.5}, {3, 3.5}, {4, 4.5}, {4, 4.5}, {4, 4.7}, {5, 5.5}, {6, 6.5}, {7, 7.5}, {8, 8.5}}));
|
||||
|
||||
std::same_as<I> decltype(auto) i3 = m.erase(std::next(m.cbegin(), 8));
|
||||
assert(m.size() == 8);
|
||||
assert(i3 == m.end());
|
||||
assert(std::ranges::equal(
|
||||
m, std::vector<P>{{2, 2.5}, {3, 3.5}, {4, 4.5}, {4, 4.5}, {4, 4.7}, {5, 5.5}, {6, 6.5}, {7, 7.5}}));
|
||||
|
||||
std::same_as<I> decltype(auto) i4 = m.erase(std::next(m.begin(), 1));
|
||||
assert(m.size() == 7);
|
||||
assert(i4 == std::next(m.begin()));
|
||||
assert(std::ranges::equal(m, std::vector<P>{{2, 2.5}, {4, 4.5}, {4, 4.5}, {4, 4.7}, {5, 5.5}, {6, 6.5}, {7, 7.5}}));
|
||||
|
||||
std::same_as<I> decltype(auto) i5 = m.erase(std::next(m.cbegin(), 2));
|
||||
assert(m.size() == 6);
|
||||
assert(i5 == std::next(m.begin(), 2));
|
||||
assert(std::ranges::equal(m, std::vector<P>{{2, 2.5}, {4, 4.5}, {4, 4.7}, {5, 5.5}, {6, 6.5}, {7, 7.5}}));
|
||||
|
||||
std::same_as<I> decltype(auto) i6 = m.erase(std::next(m.begin(), 2));
|
||||
assert(m.size() == 5);
|
||||
assert(i6 == std::next(m.begin(), 2));
|
||||
assert(std::ranges::equal(m, std::vector<P>{{2, 2.5}, {4, 4.5}, {5, 5.5}, {6, 6.5}, {7, 7.5}}));
|
||||
|
||||
std::same_as<I> decltype(auto) i7 = m.erase(std::next(m.cbegin(), 0));
|
||||
assert(m.size() == 4);
|
||||
assert(i7 == std::next(m.begin(), 0));
|
||||
assert(std::ranges::equal(m, std::vector<P>{{4, 4.5}, {5, 5.5}, {6, 6.5}, {7, 7.5}}));
|
||||
|
||||
std::same_as<I> decltype(auto) i8 = m.erase(std::next(m.cbegin(), 2));
|
||||
assert(m.size() == 3);
|
||||
assert(i8 == std::next(m.begin(), 2));
|
||||
assert(std::ranges::equal(m, std::vector<P>{{4, 4.5}, {5, 5.5}, {7, 7.5}}));
|
||||
|
||||
std::same_as<I> decltype(auto) i9 = m.erase(std::next(m.cbegin(), 2));
|
||||
assert(m.size() == 2);
|
||||
assert(i9 == std::next(m.begin(), 2));
|
||||
assert(std::ranges::equal(m, std::vector<P>{{4, 4.5}, {5, 5.5}}));
|
||||
|
||||
std::same_as<I> decltype(auto) i10 = m.erase(m.cbegin());
|
||||
assert(m.size() == 1);
|
||||
assert(i10 == m.cbegin());
|
||||
assert(std::ranges::equal(m, std::vector<P>{{5, 5.5}}));
|
||||
|
||||
std::same_as<I> decltype(auto) i11 = m.erase(m.begin());
|
||||
assert(m.size() == 0);
|
||||
assert(i11 == m.begin());
|
||||
assert(i11 == m.end());
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
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>>>();
|
||||
|
||||
{
|
||||
auto erase_function = [](auto& m, auto) { m.erase(m.begin() + 2); };
|
||||
test_erase_exception_guarantee(erase_function);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// iterator erase(const_iterator first, const_iterator last);
|
||||
|
||||
#include <compare>
|
||||
#include <concepts>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
using P = std::pair<Key, Value>;
|
||||
using I = M::iterator;
|
||||
|
||||
P ar[] = {
|
||||
P(1, 1.5),
|
||||
P(2, 2.5),
|
||||
P(2, 2.6),
|
||||
P(3, 3.5),
|
||||
P(3, 3.6),
|
||||
P(3, 3.7),
|
||||
P(4, 4.5),
|
||||
P(5, 5.5),
|
||||
P(6, 6.5),
|
||||
P(7, 7.5),
|
||||
P(8, 8.5),
|
||||
};
|
||||
M m(ar, ar + sizeof(ar) / sizeof(ar[0]));
|
||||
assert(m.size() == 11);
|
||||
std::same_as<I> decltype(auto) i1 = m.erase(m.cbegin(), m.cbegin());
|
||||
assert(m.size() == 11);
|
||||
assert(i1 == m.begin());
|
||||
assert(std::ranges::equal(
|
||||
m,
|
||||
std::vector<P>{
|
||||
{1, 1.5},
|
||||
{2, 2.5},
|
||||
{2, 2.6},
|
||||
{3, 3.5},
|
||||
{3, 3.6},
|
||||
{3, 3.7},
|
||||
{4, 4.5},
|
||||
{5, 5.5},
|
||||
{6, 6.5},
|
||||
{7, 7.5},
|
||||
{8, 8.5}}));
|
||||
|
||||
std::same_as<I> decltype(auto) i2 = m.erase(m.cbegin(), std::next(m.cbegin(), 2));
|
||||
assert(m.size() == 9);
|
||||
assert(i2 == m.begin());
|
||||
assert(std::ranges::equal(
|
||||
m, std::vector<P>{{2, 2.6}, {3, 3.5}, {3, 3.6}, {3, 3.7}, {4, 4.5}, {5, 5.5}, {6, 6.5}, {7, 7.5}, {8, 8.5}}));
|
||||
|
||||
std::same_as<I> decltype(auto) i3 = m.erase(std::next(m.cbegin(), 2), std::next(m.cbegin(), 6));
|
||||
assert(m.size() == 5);
|
||||
assert(i3 == std::next(m.begin(), 2));
|
||||
assert(std::ranges::equal(m, std::vector<P>{{2, 2.6}, {3, 3.5}, {6, 6.5}, {7, 7.5}, {8, 8.5}}));
|
||||
|
||||
std::same_as<I> decltype(auto) i4 = m.erase(m.cbegin(), m.cend());
|
||||
assert(m.size() == 0);
|
||||
assert(i4 == m.begin());
|
||||
assert(i4 == m.end());
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
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>>>();
|
||||
|
||||
{
|
||||
auto erase_function = [](auto& m, auto) { m.erase(m.begin(), m.begin() + 2); };
|
||||
test_erase_exception_guarantee(erase_function);
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// size_type erase(const key_type& k);
|
||||
|
||||
#include <compare>
|
||||
#include <concepts>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer, class Compare = std::less<>>
|
||||
void test() {
|
||||
using M = std::flat_multimap<int, char, Compare, KeyContainer, ValueContainer>;
|
||||
|
||||
auto make = [](std::initializer_list<int> il) {
|
||||
M m;
|
||||
for (int i : il) {
|
||||
m.emplace(i, i);
|
||||
}
|
||||
return m;
|
||||
};
|
||||
M m = make({1, 1, 2, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8, 8, 8, 9});
|
||||
ASSERT_SAME_TYPE(decltype(m.erase(9)), typename M::size_type);
|
||||
auto n = m.erase(10);
|
||||
assert(n == 0);
|
||||
assert(m == make({1, 1, 2, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8, 8, 8, 9}));
|
||||
n = m.erase(4);
|
||||
assert(n == 1);
|
||||
assert(m == make({1, 1, 2, 2, 2, 3, 5, 5, 6, 7, 8, 8, 8, 8, 9}));
|
||||
n = m.erase(1);
|
||||
assert(n == 2);
|
||||
assert(m == make({2, 2, 2, 3, 5, 5, 6, 7, 8, 8, 8, 8, 9}));
|
||||
n = m.erase(8);
|
||||
assert(n == 4);
|
||||
assert(m == make({2, 2, 2, 3, 5, 5, 6, 7, 9}));
|
||||
n = m.erase(3);
|
||||
assert(n == 1);
|
||||
assert(m == make({2, 2, 2, 5, 5, 6, 7, 9}));
|
||||
n = m.erase(4);
|
||||
assert(n == 0);
|
||||
assert(m == make({2, 2, 2, 5, 5, 6, 7, 9}));
|
||||
n = m.erase(6);
|
||||
assert(n == 1);
|
||||
assert(m == make({2, 2, 2, 5, 5, 7, 9}));
|
||||
n = m.erase(7);
|
||||
assert(n == 1);
|
||||
assert(m == make({2, 2, 2, 5, 5, 9}));
|
||||
n = m.erase(2);
|
||||
assert(n == 3);
|
||||
assert(m == make({5, 5, 9}));
|
||||
n = m.erase(5);
|
||||
assert(n == 2);
|
||||
assert(m == make({9}));
|
||||
n = m.erase(9);
|
||||
assert(n == 1);
|
||||
assert(m.empty());
|
||||
n = m.erase(1);
|
||||
assert(n == 0);
|
||||
assert(m.empty());
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<int>, std::vector<char>>();
|
||||
test<std::vector<int>, std::vector<char>, std::greater<>>();
|
||||
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>>>();
|
||||
|
||||
{
|
||||
auto erase_function = [](auto& m, auto key_arg) {
|
||||
using Map = std::decay_t<decltype(m)>;
|
||||
using Key = typename Map::key_type;
|
||||
const Key key{key_arg};
|
||||
m.erase(key);
|
||||
};
|
||||
test_erase_exception_guarantee(erase_function);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,161 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// size_type erase(K&& k);
|
||||
|
||||
#include <compare>
|
||||
#include <concepts>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
// Constraints: The qualified-id Compare::is_transparent is valid and denotes a type.
|
||||
template <class M>
|
||||
concept CanErase = requires(M m, Transparent<int> k) { m.erase(k); };
|
||||
using TransparentMap = std::flat_multimap<int, double, TransparentComparator>;
|
||||
using NonTransparentMap = std::flat_multimap<int, double, NonTransparentComparator>;
|
||||
static_assert(CanErase<TransparentMap>);
|
||||
static_assert(!CanErase<const TransparentMap>);
|
||||
static_assert(!CanErase<NonTransparentMap>);
|
||||
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; }
|
||||
friend bool operator<(const HeterogeneousKey&, const HeterogeneousKey&) {
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
Key key_;
|
||||
It it_;
|
||||
};
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test_simple() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::ranges::less, KeyContainer, ValueContainer>;
|
||||
|
||||
M m = {{1, 1}, {2, 2}, {2, 2}, {3, 3}, {3, 4}, {3, 5}, {4, 4}};
|
||||
ASSERT_SAME_TYPE(decltype(m.erase(9)), typename M::size_type);
|
||||
auto n = m.erase(3); // erase(K&&) [with K=int]
|
||||
assert(n == 3);
|
||||
assert((m == M{{1, 1}, {2, 2}, {2, 2}, {4, 4}}));
|
||||
typename M::key_type lvalue = 2;
|
||||
n = m.erase(lvalue); // erase(K&&) [with K=int&]
|
||||
assert(n == 2);
|
||||
assert((m == M{{1, 1}, {4, 4}}));
|
||||
const typename M::key_type const_lvalue = 1;
|
||||
n = m.erase(const_lvalue); // erase(const key_type&)
|
||||
assert(n == 1);
|
||||
assert((m == M{{4, 4}}));
|
||||
}
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test_transparent_comparator() {
|
||||
using M = std::flat_multimap<std::string, int, TransparentComparator, KeyContainer, ValueContainer>;
|
||||
using P = std::pair<std::string, int>;
|
||||
M m = {
|
||||
{"alpha", 1}, {"beta", 2}, {"epsilon", 3}, {"epsilon", 4}, {"eta", 4}, {"gamma", 5}, {"gamma", 6}, {"gamma", 7}};
|
||||
ASSERT_SAME_TYPE(decltype(m.erase(Transparent<std::string>{"abc"})), typename M::size_type);
|
||||
|
||||
auto n = m.erase(Transparent<std::string>{"epsilon"});
|
||||
assert(n == 2);
|
||||
assert(std::ranges::equal(
|
||||
m, std::vector<P>{{"alpha", 1}, {"beta", 2}, {"eta", 4}, {"gamma", 5}, {"gamma", 6}, {"gamma", 7}}));
|
||||
|
||||
auto n2 = m.erase(Transparent<std::string>{"aaa"});
|
||||
assert(n2 == 0);
|
||||
assert(std::ranges::equal(
|
||||
m, std::vector<P>{{"alpha", 1}, {"beta", 2}, {"eta", 4}, {"gamma", 5}, {"gamma", 6}, {"gamma", 7}}));
|
||||
|
||||
auto n3 = m.erase(Transparent<std::string>{"gamma"});
|
||||
assert(n3 == 3);
|
||||
assert(std::ranges::equal(m, std::vector<P>{{"alpha", 1}, {"beta", 2}, {"eta", 4}}));
|
||||
|
||||
auto n4 = m.erase(Transparent<std::string>{"alpha"});
|
||||
assert(n4 == 1);
|
||||
assert(std::ranges::equal(m, std::vector<P>{{"beta", 2}, {"eta", 4}}));
|
||||
|
||||
auto n5 = m.erase(Transparent<std::string>{"alpha"});
|
||||
assert(n5 == 0);
|
||||
assert(std::ranges::equal(m, std::vector<P>{{"beta", 2}, {"eta", 4}}));
|
||||
|
||||
auto n6 = m.erase(Transparent<std::string>{"beta"});
|
||||
assert(n6 == 1);
|
||||
assert(std::ranges::equal(m, std::vector<P>{{"eta", 4}}));
|
||||
|
||||
auto n7 = m.erase(Transparent<std::string>{"eta"});
|
||||
assert(n7 == 1);
|
||||
assert(std::ranges::equal(m, std::vector<P>{}));
|
||||
|
||||
auto n8 = m.erase(Transparent<std::string>{"eta"});
|
||||
assert(n8 == 0);
|
||||
assert(std::ranges::equal(m, std::vector<P>{}));
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
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>>>();
|
||||
|
||||
{
|
||||
// P2077's HeterogeneousKey example
|
||||
using M = std::flat_multimap<int, int, std::less<>>;
|
||||
M m = {{1, 1}, {2, 2}, {3, 3}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {6, 6}, {7, 7}, {8, 8}, {8, 8}};
|
||||
auto h1 = HeterogeneousKey<int, M::iterator>(8, m.begin());
|
||||
std::same_as<M::size_type> auto n = m.erase(h1); // lvalue is not convertible to It; erase(K&&) is the best match
|
||||
assert(n == 2);
|
||||
assert((m == M{{1, 1}, {2, 2}, {3, 3}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {6, 6}, {7, 7}}));
|
||||
std::same_as<M::iterator> auto it = m.erase(std::move(h1)); // rvalue is convertible to It; erase(K&&) drops out
|
||||
assert(it == m.begin());
|
||||
assert((m == M{{2, 2}, {3, 3}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {6, 6}, {7, 7}}));
|
||||
}
|
||||
{
|
||||
bool transparent_used = false;
|
||||
TransparentComparator c(transparent_used);
|
||||
std::flat_multimap<int, int, TransparentComparator> m(std::sorted_equivalent, {{1, 1}, {2, 2}, {3, 3}, {3, 3}}, c);
|
||||
assert(!transparent_used);
|
||||
auto n = m.erase(Transparent<int>{3});
|
||||
assert(n == 2);
|
||||
assert(transparent_used);
|
||||
}
|
||||
{
|
||||
auto erase_transparent = [](auto& m, auto key_arg) {
|
||||
using Map = std::decay_t<decltype(m)>;
|
||||
using Key = typename Map::key_type;
|
||||
m.erase(Transparent<Key>{key_arg});
|
||||
};
|
||||
test_erase_exception_guarantee(erase_transparent);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// containers extract() &&;
|
||||
|
||||
#include <algorithm>
|
||||
#include <concepts>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class T>
|
||||
concept CanExtract = requires(T&& t) { std::forward<T>(t).extract(); };
|
||||
|
||||
static_assert(CanExtract<std::flat_multimap<int, int>&&>);
|
||||
static_assert(!CanExtract<std::flat_multimap<int, int>&>);
|
||||
static_assert(!CanExtract<std::flat_multimap<int, int> const&>);
|
||||
static_assert(!CanExtract<std::flat_multimap<int, int> const&&>);
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using M = std::flat_multimap<int, int, std::less<int>, KeyContainer, ValueContainer>;
|
||||
M m = M({1, 2, 2, 2, 3, 3}, {4, 5, 6, 7, 8, 9});
|
||||
|
||||
std::same_as<typename M::containers> auto containers = std::move(m).extract();
|
||||
|
||||
auto expected_keys = {1, 2, 2, 2, 3, 3};
|
||||
auto expected_values = {4, 5, 6, 7, 8, 9};
|
||||
assert(std::ranges::equal(containers.keys, expected_keys));
|
||||
assert(std::ranges::equal(containers.values, expected_values));
|
||||
check_invariant(m);
|
||||
LIBCPP_ASSERT(m.empty());
|
||||
LIBCPP_ASSERT(m.keys().size() == 0);
|
||||
LIBCPP_ASSERT(m.values().size() == 0);
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<int>, std::vector<int>>();
|
||||
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>>>();
|
||||
{
|
||||
// extracted object maintains invariant if one of underlying container does not clear after move
|
||||
using M = std::flat_multimap<int, int, std::less<>, std::vector<int>, CopyOnlyVector<int>>;
|
||||
M m = M({1, 2, 2, 2, 3, 3}, {1, 2, 3, 4, 5, 6});
|
||||
std::same_as<M::containers> auto containers = std::move(m).extract();
|
||||
assert(containers.keys.size() == 6);
|
||||
assert(containers.values.size() == 6);
|
||||
check_invariant(m);
|
||||
LIBCPP_ASSERT(m.empty());
|
||||
LIBCPP_ASSERT(m.keys().size() == 0);
|
||||
LIBCPP_ASSERT(m.values().size() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
using KeyContainer = std::vector<int>;
|
||||
using ValueContainer = ThrowOnMoveContainer<int>;
|
||||
using M = std::flat_multimap<int, int, std::ranges::less, KeyContainer, ValueContainer>;
|
||||
|
||||
M m;
|
||||
m.emplace(1, 1);
|
||||
m.emplace(1, 1);
|
||||
try {
|
||||
auto c = std::move(m).extract();
|
||||
assert(false);
|
||||
} catch (int) {
|
||||
check_invariant(m);
|
||||
// In libc++, we try to erase the key after value emplacement failure.
|
||||
// and after erasure failure, we clear the flat_multimap
|
||||
LIBCPP_ASSERT(m.size() == 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// iterator insert(const value_type& v);
|
||||
|
||||
#include <flat_map>
|
||||
#include <deque>
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_macros.h"
|
||||
#include "../helpers.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
using R = typename M::iterator;
|
||||
using VT = typename M::value_type;
|
||||
M m;
|
||||
|
||||
const VT v1(2, 2.5);
|
||||
std::same_as<R> decltype(auto) r = m.insert(v1);
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 1);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.5);
|
||||
|
||||
const VT v2(1, 1.5);
|
||||
r = m.insert(v2);
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 2);
|
||||
assert(r->first == 1);
|
||||
assert(r->second == 1.5);
|
||||
|
||||
const VT v3(3, 3.5);
|
||||
r = m.insert(v3);
|
||||
assert(r == m.begin() + 2);
|
||||
assert(m.size() == 3);
|
||||
assert(r->first == 3);
|
||||
assert(r->second == 3.5);
|
||||
|
||||
const VT v4(3, 4.5);
|
||||
r = m.insert(v4);
|
||||
assert(r == m.begin() + 3);
|
||||
assert(m.size() == 4);
|
||||
assert(r->first == 3);
|
||||
assert(r->second == 4.5);
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
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>>>();
|
||||
|
||||
{
|
||||
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;
|
||||
const value_type p(std::piecewise_construct, std::tuple(key_arg), std::tuple(value_arg));
|
||||
m.insert(p);
|
||||
};
|
||||
test_emplace_exception_guarantee(insert_func);
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// void insert(initializer_list<value_type> il);
|
||||
|
||||
#include <flat_map>
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <deque>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
using V = std::pair<int, double>;
|
||||
|
||||
M m = {{1, 1}, {1, 1.5}, {1, 2}, {3, 1}, {3, 1.5}, {3, 2}};
|
||||
m.insert({
|
||||
{4, 1},
|
||||
{4, 1.5},
|
||||
{4, 2},
|
||||
{1, 1},
|
||||
{1, 1.5},
|
||||
{1, 2},
|
||||
{2, 1},
|
||||
{2, 1.5},
|
||||
{2, 2},
|
||||
});
|
||||
assert(m.size() == 15);
|
||||
std::vector<V> expected = {
|
||||
{1, 1},
|
||||
{1, 1.5},
|
||||
{1, 2},
|
||||
{1, 1},
|
||||
{1, 1.5},
|
||||
{1, 2},
|
||||
{2, 1},
|
||||
{2, 1.5},
|
||||
{2, 2},
|
||||
{3, 1},
|
||||
{3, 1.5},
|
||||
{3, 2},
|
||||
{4, 1},
|
||||
{4, 1.5},
|
||||
{4, 2},
|
||||
};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
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>>>();
|
||||
|
||||
{
|
||||
auto insert_func = [](auto& m, const auto& newValues) {
|
||||
using FlatMap = std::decay_t<decltype(m)>;
|
||||
using value_type = typename FlatMap::value_type;
|
||||
std::initializer_list<value_type> il = {{newValues[0].first, newValues[0].second}};
|
||||
m.insert(il);
|
||||
};
|
||||
test_insert_range_exception_guarantee(insert_func);
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// iterator insert(const_iterator position, const value_type& v);
|
||||
|
||||
#include <flat_map>
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <deque>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_macros.h"
|
||||
#include "../helpers.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
using R = typename M::iterator;
|
||||
using VT = typename M::value_type;
|
||||
|
||||
M m;
|
||||
const VT v1(2, 2.5);
|
||||
std::same_as<R> decltype(auto) r = m.insert(m.end(), v1);
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 1);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2.5);
|
||||
|
||||
const VT v2(1, 1.5);
|
||||
r = m.insert(m.end(), v2);
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 2);
|
||||
assert(r->first == 1);
|
||||
assert(r->second == 1.5);
|
||||
|
||||
const VT v3(3, 3.5);
|
||||
r = m.insert(m.end(), v3);
|
||||
assert(r == std::ranges::prev(m.end()));
|
||||
assert(m.size() == 3);
|
||||
assert(r->first == 3);
|
||||
assert(r->second == 3.5);
|
||||
|
||||
const VT v4(3, 4.5);
|
||||
r = m.insert(m.end(), v4);
|
||||
assert(r == std::ranges::prev(m.end()));
|
||||
assert(m.size() == 4);
|
||||
assert(r->first == 3);
|
||||
assert(r->second == 4.5);
|
||||
|
||||
const VT v5(2, 5.5);
|
||||
r = m.insert(m.end(), v5);
|
||||
assert(r == m.begin() + 2);
|
||||
assert(m.size() == 5);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 5.5);
|
||||
|
||||
const VT v6(2, 6.5);
|
||||
r = m.insert(m.begin(), v6);
|
||||
assert(r == m.begin() + 1);
|
||||
assert(m.size() == 6);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 6.5);
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
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>>>();
|
||||
|
||||
{
|
||||
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;
|
||||
const value_type p(std::piecewise_construct, std::tuple(key_arg), std::tuple(value_arg));
|
||||
m.insert(m.begin(), p);
|
||||
};
|
||||
test_emplace_exception_guarantee(insert_func);
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// template <class InputIterator>
|
||||
// void insert(InputIterator first, InputIterator last);
|
||||
|
||||
#include <flat_map>
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <deque>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "test_iterators.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
// test constraint InputIterator
|
||||
template <class M, class... Args>
|
||||
concept CanInsert = requires(M m, Args&&... args) { m.insert(std::forward<Args>(args)...); };
|
||||
|
||||
using Map = std::flat_multimap<int, int>;
|
||||
using Pair = std::pair<int, int>;
|
||||
|
||||
static_assert(CanInsert<Map, Pair*, Pair*>);
|
||||
static_assert(CanInsert<Map, cpp17_input_iterator<Pair*>, cpp17_input_iterator<Pair*>>);
|
||||
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() {
|
||||
using P = std::pair<int, double>;
|
||||
using M = std::flat_multimap<int, double, std::less<int>, KeyContainer, ValueContainer>;
|
||||
|
||||
P ar1[] = {
|
||||
P(2, 1),
|
||||
P(2, 1.5),
|
||||
P(2, 2),
|
||||
P(1, 1),
|
||||
P(1, 1.5),
|
||||
P(1, 2),
|
||||
P(3, 1),
|
||||
P(3, 1.5),
|
||||
P(3, 2),
|
||||
};
|
||||
P ar2[] = {
|
||||
P(4, 1),
|
||||
P(4, 1.5),
|
||||
P(4, 2),
|
||||
P(1, 1),
|
||||
P(1, 1.5),
|
||||
P(1, 2),
|
||||
P(0, 1),
|
||||
P(0, 1.5),
|
||||
P(0, 2),
|
||||
};
|
||||
|
||||
M m;
|
||||
m.insert(cpp17_input_iterator<P*>(ar1), cpp17_input_iterator<P*>(ar1 + sizeof(ar1) / sizeof(ar1[0])));
|
||||
assert(m.size() == 9);
|
||||
std::vector<P> expected{{1, 1}, {1, 1.5}, {1, 2}, {2, 1}, {2, 1.5}, {2, 2}, {3, 1}, {3, 1.5}, {3, 2}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
|
||||
m.insert(cpp17_input_iterator<P*>(ar2), cpp17_input_iterator<P*>(ar2 + sizeof(ar2) / sizeof(ar2[0])));
|
||||
assert(m.size() == 18);
|
||||
std::vector<P> expected2{
|
||||
{0, 1},
|
||||
{0, 1.5},
|
||||
{0, 2},
|
||||
{1, 1},
|
||||
{1, 1.5},
|
||||
{1, 2},
|
||||
{1, 1},
|
||||
{1, 1.5},
|
||||
{1, 2},
|
||||
{2, 1},
|
||||
{2, 1.5},
|
||||
{2, 2},
|
||||
{3, 1},
|
||||
{3, 1.5},
|
||||
{3, 2},
|
||||
{4, 1},
|
||||
{4, 1.5},
|
||||
{4, 2}};
|
||||
assert(std::ranges::equal(m, expected2));
|
||||
}
|
||||
int main(int, char**) {
|
||||
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>>>();
|
||||
|
||||
{
|
||||
auto insert_func = [](auto& m, const auto& newValues) { m.insert(newValues.begin(), newValues.end()); };
|
||||
test_insert_range_exception_guarantee(insert_func);
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// iterator insert(const_iterator position, value_type&&);
|
||||
|
||||
#include <flat_map>
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "MoveOnly.h"
|
||||
#include "min_allocator.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
|
||||
template <class Container, class Pair>
|
||||
void do_insert_iter_rv_test() {
|
||||
using M = Container;
|
||||
using P = Pair;
|
||||
using R = typename M::iterator;
|
||||
M m;
|
||||
std::same_as<R> decltype(auto) r = m.insert(m.end(), P(2, 2));
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 1);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2);
|
||||
|
||||
r = m.insert(m.end(), P(1, 1));
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 2);
|
||||
assert(r->first == 1);
|
||||
assert(r->second == 1);
|
||||
|
||||
r = m.insert(m.end(), P(3, 3));
|
||||
assert(r == std::ranges::prev(m.end()));
|
||||
assert(m.size() == 3);
|
||||
assert(r->first == 3);
|
||||
assert(r->second == 3);
|
||||
|
||||
r = m.insert(m.end(), P(3, 4));
|
||||
assert(r == std::ranges::prev(m.end()));
|
||||
assert(m.size() == 4);
|
||||
assert(r->first == 3);
|
||||
assert(r->second == 4);
|
||||
|
||||
r = m.insert(m.end(), P(2, 5));
|
||||
assert(r == m.begin() + 2);
|
||||
assert(m.size() == 5);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 5);
|
||||
|
||||
r = m.insert(m.begin(), P(2, 6));
|
||||
assert(r == m.begin() + 1);
|
||||
assert(m.size() == 6);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 6);
|
||||
}
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
using P = std::pair<Key, Value>;
|
||||
using CP = std::pair<const Key, Value>;
|
||||
|
||||
do_insert_iter_rv_test<M, P>();
|
||||
do_insert_iter_rv_test<M, CP>();
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
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>>();
|
||||
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>>>();
|
||||
|
||||
{
|
||||
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;
|
||||
value_type p(std::piecewise_construct, std::tuple(key_arg), std::tuple(value_arg));
|
||||
m.insert(m.begin(), std::move(p));
|
||||
};
|
||||
test_emplace_exception_guarantee(insert_func);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// template<container-compatible-range<value_type> R>
|
||||
// void insert_range(R&& rg);
|
||||
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "MoveOnly.h"
|
||||
#include "test_macros.h"
|
||||
#include "test_iterators.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
// test constraint container-compatible-range
|
||||
template <class M, class R>
|
||||
concept CanInsertRange = requires(M m, R&& r) { m.insert_range(std::forward<R>(r)); };
|
||||
|
||||
using Map = std::flat_multimap<int, double>;
|
||||
|
||||
static_assert(CanInsertRange<Map, std::ranges::subrange<std::pair<int, double>*>>);
|
||||
static_assert(CanInsertRange<Map, std::ranges::subrange<std::pair<short, double>*>>);
|
||||
static_assert(!CanInsertRange<Map, std::ranges::subrange<int*>>);
|
||||
static_assert(!CanInsertRange<Map, std::ranges::subrange<double*>>);
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
|
||||
{
|
||||
using P = std::pair<int, int>;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
using It = forward_iterator<const P*>;
|
||||
M m = {{10, 1}, {8, 2}, {5, 3}, {2, 4}, {1, 5}};
|
||||
P ar[] = {{3, 1}, {1, 2}, {4, 3}, {1, 4}, {5, 5}, {9, 6}};
|
||||
std::ranges::subrange r = {It(ar), It(ar + 6)};
|
||||
static_assert(std::ranges::common_range<decltype(r)>);
|
||||
m.insert_range(r);
|
||||
std::vector<P> expected = {{1, 5}, {1, 2}, {1, 4}, {2, 4}, {3, 1}, {4, 3}, {5, 3}, {5, 5}, {8, 2}, {9, 6}, {10, 1}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
}
|
||||
{
|
||||
using P = std::pair<int, int>;
|
||||
using M = std::flat_multimap<Key, Value, std::greater<>, KeyContainer, ValueContainer>;
|
||||
using It = cpp20_input_iterator<const P*>;
|
||||
M m = {{8, 1}, {5, 2}, {3, 3}, {2, 4}};
|
||||
P ar[] = {{3, 1}, {1, 2}, {4, 3}, {1, 4}, {5, 5}, {9, 6}};
|
||||
std::ranges::subrange r = {It(ar), sentinel_wrapper<It>(It(ar + 6))};
|
||||
static_assert(!std::ranges::common_range<decltype(r)>);
|
||||
m.insert_range(r);
|
||||
std::vector<P> expected = {{9, 6}, {8, 1}, {5, 2}, {5, 5}, {4, 3}, {3, 3}, {3, 1}, {2, 4}, {1, 2}, {1, 4}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<int>, std::vector<int>>();
|
||||
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>>>();
|
||||
{
|
||||
// Items are forwarded correctly from the input range (P2767).
|
||||
std::pair<MoveOnly, MoveOnly> a[] = {{3, 3}, {1, 1}, {4, 4}, {1, 1}, {5, 5}};
|
||||
std::flat_multimap<MoveOnly, MoveOnly> m;
|
||||
m.insert_range(a | std::views::as_rvalue);
|
||||
std::pair<MoveOnly, MoveOnly> expected[] = {{1, 1}, {1, 1}, {3, 3}, {4, 4}, {5, 5}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
}
|
||||
{
|
||||
// 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::flat_multimap<int, int> m;
|
||||
m.insert_range(a);
|
||||
std::pair<int, int> expected[] = {{1, 1}, {1, 1}, {3, 3}, {4, 4}, {5, 5}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
}
|
||||
{
|
||||
auto insert_func = [](auto& m, const auto& newValues) { m.insert_range(newValues); };
|
||||
test_insert_range_exception_guarantee(insert_func);
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// iterator insert( value_type&& v);
|
||||
|
||||
#include <flat_map>
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "MoveOnly.h"
|
||||
#include "min_allocator.h"
|
||||
#include "test_macros.h"
|
||||
#include "../helpers.h"
|
||||
|
||||
template <class Container, class Pair>
|
||||
void do_insert_rv_test() {
|
||||
using M = Container;
|
||||
using P = Pair;
|
||||
using R = typename M::iterator;
|
||||
M m;
|
||||
std::same_as<R> decltype(auto) r = m.insert(P(2, 2));
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 1);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2);
|
||||
|
||||
r = m.insert(P(1, 1));
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 2);
|
||||
assert(r->first == 1);
|
||||
assert(r->second == 1);
|
||||
|
||||
r = m.insert(P(3, 3));
|
||||
assert(r == std::ranges::prev(m.end()));
|
||||
assert(m.size() == 3);
|
||||
assert(r->first == 3);
|
||||
assert(r->second == 3);
|
||||
|
||||
r = m.insert(P(3, 3));
|
||||
assert(r == std::ranges::prev(m.end()));
|
||||
assert(m.size() == 4);
|
||||
assert(r->first == 3);
|
||||
assert(r->second == 3);
|
||||
}
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
|
||||
|
||||
using P = std::pair<Key, Value>;
|
||||
using CP = std::pair<const Key, Value>;
|
||||
|
||||
do_insert_rv_test<M, P>();
|
||||
do_insert_rv_test<M, CP>();
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<int>, std::vector<MoveOnly>>();
|
||||
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>>>();
|
||||
|
||||
{
|
||||
using M = std::flat_multimap<int, MoveOnly>;
|
||||
using R = M::iterator;
|
||||
M m;
|
||||
R r = m.insert({2, MoveOnly(2)});
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 1);
|
||||
assert(r->first == 2);
|
||||
assert(r->second == 2);
|
||||
|
||||
r = m.insert({1, MoveOnly(1)});
|
||||
assert(r == m.begin());
|
||||
assert(m.size() == 2);
|
||||
assert(r->first == 1);
|
||||
assert(r->second == 1);
|
||||
|
||||
r = m.insert({3, MoveOnly(3)});
|
||||
assert(r == std::ranges::prev(m.end()));
|
||||
assert(m.size() == 3);
|
||||
assert(r->first == 3);
|
||||
assert(r->second == 3);
|
||||
|
||||
r = m.insert({3, MoveOnly(3)});
|
||||
assert(r == std::ranges::prev(m.end()));
|
||||
assert(m.size() == 4);
|
||||
assert(r->first == 3);
|
||||
assert(r->second == 3);
|
||||
}
|
||||
{
|
||||
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;
|
||||
value_type p(std::piecewise_construct, std::tuple(key_arg), std::tuple(value_arg));
|
||||
m.insert(std::move(p));
|
||||
};
|
||||
test_emplace_exception_guarantee(insert_func);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// void insert(sorted_equivalent_t, initializer_list<value_type> il);
|
||||
|
||||
#include <flat_map>
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <deque>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
|
||||
using V = std::pair<const Key, Value>;
|
||||
M m = {{1, 1}, {1, 1.5}, {1, 2}, {3, 1}, {3, 1.5}, {3, 2}};
|
||||
m.insert(std::sorted_equivalent,
|
||||
{
|
||||
{0, 1},
|
||||
{1, 2},
|
||||
{1, 3},
|
||||
{2, 1},
|
||||
{2, 4},
|
||||
{4, 1},
|
||||
});
|
||||
assert(m.size() == 12);
|
||||
V expected[] = {{0, 1}, {1, 1}, {1, 1.5}, {1, 2}, {1, 2}, {1, 3}, {2, 1}, {2, 4}, {3, 1}, {3, 1.5}, {3, 2}, {4, 1}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
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>>>();
|
||||
|
||||
{
|
||||
auto insert_func = [](auto& m, const auto& newValues) {
|
||||
using FlatMap = std::decay_t<decltype(m)>;
|
||||
using value_type = typename FlatMap::value_type;
|
||||
std::initializer_list<value_type> il = {{newValues[0].first, newValues[0].second}};
|
||||
m.insert(std::sorted_equivalent, il);
|
||||
};
|
||||
test_insert_range_exception_guarantee(insert_func);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// template <class InputIterator>
|
||||
// void insert(sorted_equivalent_t, InputIterator first, InputIterator last);
|
||||
|
||||
#include <flat_map>
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <deque>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "test_iterators.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
// test constraint InputIterator
|
||||
template <class M, class... Args>
|
||||
concept CanInsert = requires(M m, Args&&... args) { m.insert(std::forward<Args>(args)...); };
|
||||
|
||||
using Map = std::flat_multimap<int, int>;
|
||||
using Pair = std::pair<int, int>;
|
||||
|
||||
static_assert(CanInsert<Map, std::sorted_equivalent_t, Pair*, Pair*>);
|
||||
static_assert(CanInsert<Map, std::sorted_equivalent_t, cpp17_input_iterator<Pair*>, cpp17_input_iterator<Pair*>>);
|
||||
static_assert(!CanInsert<Map, std::sorted_equivalent_t, int, int>);
|
||||
static_assert(!CanInsert<Map, std::sorted_equivalent_t, cpp20_input_iterator<Pair*>, cpp20_input_iterator<Pair*>>);
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
using P = std::pair<Key, Value>;
|
||||
|
||||
P ar1[] = {
|
||||
P(1, 1),
|
||||
P(1, 0),
|
||||
P(2, 1),
|
||||
P(2, 3),
|
||||
P(3, 1),
|
||||
};
|
||||
|
||||
P ar2[] = {
|
||||
P(0, 1),
|
||||
P(2, 2),
|
||||
P(2, 5),
|
||||
P(4, 1),
|
||||
P(4, 4),
|
||||
};
|
||||
|
||||
M m;
|
||||
m.insert(std::sorted_equivalent,
|
||||
cpp17_input_iterator<P*>(ar1),
|
||||
cpp17_input_iterator<P*>(ar1 + sizeof(ar1) / sizeof(ar1[0])));
|
||||
assert(m.size() == 5);
|
||||
P expected[] = {{1, 1}, {1, 0}, {2, 1}, {2, 3}, {3, 1}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
|
||||
m.insert(std::sorted_equivalent,
|
||||
cpp17_input_iterator<P*>(ar2),
|
||||
cpp17_input_iterator<P*>(ar2 + sizeof(ar2) / sizeof(ar2[0])));
|
||||
assert(m.size() == 10);
|
||||
P expected2[] = {{0, 1}, {1, 1}, {1, 0}, {2, 1}, {2, 3}, {2, 2}, {2, 5}, {3, 1}, {4, 1}, {4, 4}};
|
||||
assert(std::ranges::equal(m, expected2));
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
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>>>();
|
||||
|
||||
{
|
||||
auto insert_func = [](auto& m, const auto& newValues) {
|
||||
m.insert(std::sorted_equivalent, newValues.begin(), newValues.end());
|
||||
};
|
||||
test_insert_range_exception_guarantee(insert_func);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// template<class K> iterator insert(P&& x);
|
||||
// template<class K> iterator insert(const_iterator hint, P&& x);
|
||||
|
||||
#include <algorithm>
|
||||
#include <compare>
|
||||
#include <concepts>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <tuple>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "test_iterators.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
// Constraints: is_constructible_v<pair<key_type, mapped_type>, P> is true.
|
||||
template <class M, class... Args>
|
||||
concept CanInsert = requires(M m, Args&&... args) { m.insert(std::forward<Args>(args)...); };
|
||||
|
||||
using Map = std::flat_multimap<int, double>;
|
||||
using Iter = Map::const_iterator;
|
||||
|
||||
static_assert(CanInsert<Map, std::pair<short, double>&&>);
|
||||
static_assert(CanInsert<Map, Iter, std::pair<short, double>&&>);
|
||||
static_assert(CanInsert<Map, std::tuple<short, double>&&>);
|
||||
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_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
|
||||
{
|
||||
// insert(P&&)
|
||||
// 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}, {3, 1}, {3, 4}, {4, 4}, {5, 5}};
|
||||
expensive_comparisons = 0;
|
||||
cheap_comparisons = 0;
|
||||
std::same_as<typename M::iterator> decltype(auto) r = m.insert(std::make_pair(3, 3)); // conversion happens first
|
||||
assert(expensive_comparisons >= 2);
|
||||
assert(cheap_comparisons == 0);
|
||||
assert(r == m.begin() + 4);
|
||||
|
||||
std::pair<int, int> expected[] = {{1, 1}, {2, 2}, {3, 1}, {3, 4}, {3, 3}, {4, 4}, {5, 5}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
}
|
||||
{
|
||||
// insert(const_iterator, P&&)
|
||||
M m = {{1, 1}, {2, 2}, {3, 1}, {3, 4}, {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);
|
||||
std::pair<int, int> expected[] = {{1, 1}, {2, 2}, {3, 3}, {3, 1}, {3, 4}, {4, 4}, {5, 5}};
|
||||
assert(std::ranges::equal(m, expected));
|
||||
}
|
||||
}
|
||||
|
||||
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>>>();
|
||||
|
||||
{
|
||||
// no ambiguity between insert(pos, P&&) and insert(first, last)
|
||||
using M = std::flat_multimap<int, int>;
|
||||
struct Evil {
|
||||
operator M::value_type() const;
|
||||
operator M::const_iterator() const;
|
||||
};
|
||||
std::flat_multimap<int, int> m;
|
||||
ASSERT_SAME_TYPE(decltype(m.insert(Evil())), M::iterator);
|
||||
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);
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// void replace(key_container_type&& key_cont, mapped_container_type&& mapped_cont);
|
||||
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <concepts>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class T, class... Args>
|
||||
concept CanReplace = requires(T t, Args&&... args) { t.replace(std::forward<Args>(args)...); };
|
||||
|
||||
using Map = std::flat_multimap<int, int>;
|
||||
static_assert(CanReplace<Map, std::vector<int>, std::vector<int>>);
|
||||
static_assert(!CanReplace<Map, const std::vector<int>&, std::vector<int>>);
|
||||
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() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
|
||||
M m = M({1, 1, 3}, {4, 5, 6});
|
||||
KeyContainer new_keys = {7, 7};
|
||||
ValueContainer new_values = {9, 10};
|
||||
auto expected_keys = new_keys;
|
||||
auto expected_values = new_values;
|
||||
m.replace(std::move(new_keys), std::move(new_values));
|
||||
assert(m.size() == 2);
|
||||
assert(std::ranges::equal(m.keys(), expected_keys));
|
||||
assert(std::ranges::equal(m.values(), expected_values));
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
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>>>();
|
||||
|
||||
{
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
using KeyContainer = std::vector<int>;
|
||||
using ValueContainer = ThrowOnMoveContainer<int>;
|
||||
using M = std::flat_multimap<int, int, std::ranges::less, KeyContainer, ValueContainer>;
|
||||
|
||||
M m;
|
||||
m.emplace(1, 1);
|
||||
m.emplace(2, 2);
|
||||
try {
|
||||
KeyContainer new_keys{3, 4};
|
||||
ValueContainer new_values{5, 6};
|
||||
m.replace(std::move(new_keys), std::move(new_values));
|
||||
assert(false);
|
||||
} catch (int) {
|
||||
check_invariant(m);
|
||||
// In libc++, we clear the map
|
||||
LIBCPP_ASSERT(m.size() == 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
// `check_assertion.h` requires Unix headers and regex support.
|
||||
// REQUIRES: has-unix-headers
|
||||
// UNSUPPORTED: no-localization
|
||||
// UNSUPPORTED: no-exceptions
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// void swap(flat_multimap& y) noexcept;
|
||||
// friend void swap(flat_multimap& x, flat_multimap& y) noexcept
|
||||
|
||||
// Test that std::terminate is called if any exception is thrown during swap
|
||||
|
||||
#include <flat_map>
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "../helpers.h"
|
||||
#include "check_assertion.h"
|
||||
|
||||
template <class F>
|
||||
void test_swap_exception_guarantee([[maybe_unused]] F&& swap_function) {
|
||||
{
|
||||
// key swap throws
|
||||
using KeyContainer = ThrowOnMoveContainer<int>;
|
||||
using ValueContainer = std::vector<int>;
|
||||
using M = std::flat_multimap<int, int, TransparentComparator, KeyContainer, ValueContainer>;
|
||||
|
||||
M m1, m2;
|
||||
m1.emplace(1, 1);
|
||||
m1.emplace(1, 2);
|
||||
m2.emplace(3, 3);
|
||||
m2.emplace(3, 4);
|
||||
// swap is noexcept
|
||||
EXPECT_STD_TERMINATE([&] { swap_function(m1, m2); });
|
||||
}
|
||||
|
||||
{
|
||||
// value swap throws
|
||||
using KeyContainer = std::vector<int>;
|
||||
using ValueContainer = ThrowOnMoveContainer<int>;
|
||||
using M = std::flat_multimap<int, int, TransparentComparator, KeyContainer, ValueContainer>;
|
||||
|
||||
M m1, m2;
|
||||
m1.emplace(1, 1);
|
||||
m1.emplace(1, 2);
|
||||
m2.emplace(3, 3);
|
||||
m2.emplace(3, 4);
|
||||
|
||||
// swap is noexcept
|
||||
EXPECT_STD_TERMINATE([&] { swap_function(m1, m2); });
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
auto swap_func = [](auto& m1, auto& m2) { swap(m1, m2); };
|
||||
test_swap_exception_guarantee(swap_func);
|
||||
}
|
||||
|
||||
{
|
||||
auto swap_func = [](auto& m1, auto& m2) { m1.swap(m2); };
|
||||
test_swap_exception_guarantee(swap_func);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// friend void swap(flat_multimap& x, flat_multimap& y) noexcept
|
||||
|
||||
#include <flat_map>
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "MoveOnly.h"
|
||||
#include "min_allocator.h"
|
||||
#include "test_macros.h"
|
||||
#include "../helpers.h"
|
||||
|
||||
// test noexcept
|
||||
|
||||
template <class T>
|
||||
concept NoExceptAdlSwap = requires(T t1, T t2) {
|
||||
{ swap(t1, t2) } noexcept;
|
||||
};
|
||||
|
||||
static_assert(NoExceptAdlSwap<std::flat_multimap<int, int>>);
|
||||
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
static_assert(NoExceptAdlSwap<
|
||||
std::flat_multimap<int, int, std::less<int>, ThrowOnMoveContainer<int>, ThrowOnMoveContainer<int>>>);
|
||||
#endif
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
using V = std::pair<const Key, Value>;
|
||||
|
||||
{
|
||||
M m1;
|
||||
M m2;
|
||||
M m1_save = m1;
|
||||
M m2_save = m2;
|
||||
swap(m1, m2);
|
||||
assert(m1 == m2_save);
|
||||
assert(m2 == m1_save);
|
||||
}
|
||||
{
|
||||
V ar2[] = {V(5, 5), V(5, 6), V(5, 7), V(8, 8), V(9, 9), V(10, 10), V(10, 11), V(10, 12)};
|
||||
M m1;
|
||||
M m2(ar2, ar2 + sizeof(ar2) / sizeof(ar2[0]));
|
||||
M m1_save = m1;
|
||||
M m2_save = m2;
|
||||
swap(m1, m2);
|
||||
assert(m1 == m2_save);
|
||||
assert(m2 == m1_save);
|
||||
}
|
||||
{
|
||||
V ar1[] = {V(1, 1), V(1, 2), V(3, 3), V(4, 4)};
|
||||
M m1(ar1, ar1 + sizeof(ar1) / sizeof(ar1[0]));
|
||||
M m2;
|
||||
M m1_save = m1;
|
||||
M m2_save = m2;
|
||||
swap(m1, m2);
|
||||
assert(m1 == m2_save);
|
||||
assert(m2 == m1_save);
|
||||
}
|
||||
{
|
||||
V ar1[] = {V(1, 1), V(1, 2), V(3, 3), V(4, 4)};
|
||||
V ar2[] = {V(5, 5), V(5, 6), V(5, 7), V(8, 8), V(9, 9), V(10, 10), V(10, 11), V(10, 12)};
|
||||
M m1(ar1, ar1 + sizeof(ar1) / sizeof(ar1[0]));
|
||||
M m2(ar2, ar2 + sizeof(ar2) / sizeof(ar2[0]));
|
||||
M m1_save = m1;
|
||||
M m2_save = m2;
|
||||
swap(m1, m2);
|
||||
assert(m1 == m2_save);
|
||||
assert(m2 == m1_save);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
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>>>();
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// void swap(flat_multimap& y) noexcept;
|
||||
|
||||
#include <flat_map>
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "MoveOnly.h"
|
||||
#include "min_allocator.h"
|
||||
#include "test_macros.h"
|
||||
#include "../helpers.h"
|
||||
|
||||
// test noexcept
|
||||
|
||||
template <class T>
|
||||
concept NoExceptMemberSwap = requires(T t1, T t2) {
|
||||
{ t1.swap(t2) } noexcept;
|
||||
};
|
||||
|
||||
static_assert(NoExceptMemberSwap<std::flat_multimap<int, int>>);
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
static_assert(NoExceptMemberSwap<
|
||||
std::flat_multimap<int, int, std::less<int>, ThrowOnMoveContainer<int>, ThrowOnMoveContainer<int>>>);
|
||||
#endif
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
using V = std::pair<const Key, Value>;
|
||||
{
|
||||
M m1;
|
||||
M m2;
|
||||
M m1_save = m1;
|
||||
M m2_save = m2;
|
||||
m1.swap(m2);
|
||||
assert(m1 == m2_save);
|
||||
assert(m2 == m1_save);
|
||||
}
|
||||
{
|
||||
V ar2[] = {V(5, 5), V(5, 6), V(7, 7), V(8, 8), V(9, 9), V(10, 10), V(10, 11), V(12, 12)};
|
||||
M m1;
|
||||
M m2(ar2, ar2 + sizeof(ar2) / sizeof(ar2[0]));
|
||||
M m1_save = m1;
|
||||
M m2_save = m2;
|
||||
m1.swap(m2);
|
||||
assert(m1 == m2_save);
|
||||
assert(m2 == m1_save);
|
||||
}
|
||||
{
|
||||
V ar1[] = {V(1, 1), V(1, 2), V(3, 3), V(4, 4)};
|
||||
M m1(ar1, ar1 + sizeof(ar1) / sizeof(ar1[0]));
|
||||
M m2;
|
||||
M m1_save = m1;
|
||||
M m2_save = m2;
|
||||
m1.swap(m2);
|
||||
assert(m1 == m2_save);
|
||||
assert(m2 == m1_save);
|
||||
}
|
||||
{
|
||||
V ar1[] = {V(1, 1), V(1, 2), V(3, 3), V(4, 4)};
|
||||
V ar2[] = {V(5, 5), V(5, 6), V(7, 7), V(8, 8), V(9, 9), V(10, 10), V(10, 11), V(12, 12)};
|
||||
M m1(ar1, ar1 + sizeof(ar1) / sizeof(ar1[0]));
|
||||
M m2(ar2, ar2 + sizeof(ar2) / sizeof(ar2[0]));
|
||||
M m1_save = m1;
|
||||
M m2_save = m2;
|
||||
m1.swap(m2);
|
||||
assert(m1 == m2_save);
|
||||
assert(m2 == m1_save);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
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>>>();
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// key_compare key_comp() const;
|
||||
// value_compare value_comp() const;
|
||||
|
||||
#include <cassert>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
int main(int, char**) {
|
||||
{
|
||||
using M = std::flat_multimap<int, char>;
|
||||
using Comp = std::less<int>; // the default
|
||||
M m = {};
|
||||
ASSERT_SAME_TYPE(M::key_compare, Comp);
|
||||
static_assert(!std::is_same_v<M::value_compare, Comp>);
|
||||
ASSERT_SAME_TYPE(decltype(m.key_comp()), Comp);
|
||||
ASSERT_SAME_TYPE(decltype(m.value_comp()), M::value_compare);
|
||||
Comp kc = m.key_comp();
|
||||
assert(kc(1, 2));
|
||||
assert(!kc(2, 1));
|
||||
auto vc = m.value_comp();
|
||||
ASSERT_SAME_TYPE(decltype(vc(std::make_pair(1, 2), std::make_pair(1, 2))), bool);
|
||||
assert(vc({1, '2'}, {2, '1'}));
|
||||
assert(!vc({2, '1'}, {1, '2'}));
|
||||
}
|
||||
{
|
||||
using Comp = std::function<bool(int, int)>;
|
||||
using M = std::flat_multimap<int, int, Comp>;
|
||||
Comp comp = std::greater<int>();
|
||||
M m({}, comp);
|
||||
ASSERT_SAME_TYPE(M::key_compare, Comp);
|
||||
ASSERT_SAME_TYPE(decltype(m.key_comp()), Comp);
|
||||
ASSERT_SAME_TYPE(decltype(m.value_comp()), M::value_compare);
|
||||
Comp kc = m.key_comp();
|
||||
assert(!kc(1, 2));
|
||||
assert(kc(2, 1));
|
||||
auto vc = m.value_comp();
|
||||
auto a = std::make_pair(1, 2);
|
||||
ASSERT_SAME_TYPE(decltype(vc(a, a)), bool);
|
||||
static_assert(!noexcept(vc(a, a)));
|
||||
assert(!vc({1, 2}, {2, 1}));
|
||||
assert(vc({2, 1}, {1, 2}));
|
||||
}
|
||||
{
|
||||
using Comp = std::less<>;
|
||||
using M = std::flat_multimap<int, int, Comp>;
|
||||
M m = {};
|
||||
ASSERT_SAME_TYPE(M::key_compare, Comp);
|
||||
ASSERT_SAME_TYPE(decltype(m.key_comp()), Comp);
|
||||
ASSERT_SAME_TYPE(decltype(m.value_comp()), M::value_compare);
|
||||
Comp kc = m.key_comp();
|
||||
assert(kc(1, 2));
|
||||
assert(!kc(2, 1));
|
||||
auto vc = m.value_comp();
|
||||
auto a = std::make_pair(1, 2);
|
||||
ASSERT_SAME_TYPE(decltype(vc(a, a)), bool);
|
||||
assert(vc({1, 2}, {2, 1}));
|
||||
assert(!vc({2, 1}, {1, 2}));
|
||||
}
|
||||
{
|
||||
using Comp = std::function<bool(const std::vector<int>&, const std::vector<int>&)>;
|
||||
using M = std::flat_multimap<std::vector<int>, int, Comp>;
|
||||
Comp comp = [i = 1](const auto& x, const auto& y) { return x[i] < y[i]; };
|
||||
M m({}, comp);
|
||||
auto vc = m.value_comp();
|
||||
static_assert(sizeof(vc) >= sizeof(Comp));
|
||||
comp = nullptr;
|
||||
m = M({}, nullptr);
|
||||
assert(m.key_comp() == nullptr);
|
||||
// At this point, m.key_comp() is disengaged.
|
||||
// But the std::function captured by copy inside `vc` remains valid.
|
||||
auto a = std::make_pair(std::vector<int>{2, 1, 4}, 42);
|
||||
auto b = std::make_pair(std::vector<int>{1, 2, 3}, 42);
|
||||
auto c = std::make_pair(std::vector<int>{0, 3, 2}, 42);
|
||||
assert(vc(a, b));
|
||||
assert(vc(b, c));
|
||||
assert(!vc(b, a));
|
||||
assert(!vc(c, b));
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// const key_container_type& keys() const noexcept
|
||||
// const mapped_container_type& values() const noexcept
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_macros.h"
|
||||
#include "test_allocator.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
|
||||
const M m = {{4, 'a'}, {2, 'b'}, {2, 'e'}, {3, 'c'}};
|
||||
std::same_as<const KeyContainer&> decltype(auto) keys = m.keys();
|
||||
std::same_as<const ValueContainer&> decltype(auto) values = m.values();
|
||||
|
||||
// noexcept
|
||||
static_assert(noexcept(m.keys()));
|
||||
static_assert(noexcept(m.values()));
|
||||
|
||||
auto expected_keys = {2, 2, 3, 4};
|
||||
auto expected_values = {'b', 'e', 'c', 'a'};
|
||||
assert(std::ranges::equal(keys, expected_keys));
|
||||
assert(std::ranges::equal(values, expected_values));
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<int>, std::vector<char>>();
|
||||
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 0;
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// bool contains(const key_type& x) const;
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
{
|
||||
using M = std::flat_multimap<Key, Value, std::less<>, KeyContainer, ValueContainer>;
|
||||
M m = {{1, 1}, {2, 2}, {2, 3}, {4, 4}, {5, 5}, {8, 1}, {8, 2}, {8, 8}};
|
||||
assert(!m.contains(0));
|
||||
assert(m.contains(1));
|
||||
assert(m.contains(2));
|
||||
assert(!m.contains(3));
|
||||
assert(m.contains(4));
|
||||
assert(m.contains(5));
|
||||
assert(!m.contains(6));
|
||||
assert(!m.contains(7));
|
||||
assert(std::as_const(m).contains(8));
|
||||
assert(!std::as_const(m).contains(9));
|
||||
m.clear();
|
||||
assert(!m.contains(1));
|
||||
}
|
||||
{
|
||||
using M = std::flat_multimap<Key, Value, std::greater<int>, KeyContainer, ValueContainer>;
|
||||
M m = {{1, 0}, {2, 0}, {4, 0}, {2, 1}, {5, 1}, {5, 2}, {5, 0}, {8, 0}};
|
||||
assert(!m.contains(0));
|
||||
assert(m.contains(1));
|
||||
assert(m.contains(2));
|
||||
assert(!m.contains(3));
|
||||
assert(m.contains(4));
|
||||
assert(m.contains(5));
|
||||
assert(!m.contains(6));
|
||||
assert(!m.contains(7));
|
||||
assert(std::as_const(m).contains(8));
|
||||
assert(!std::as_const(m).contains(9));
|
||||
m.clear();
|
||||
assert(!m.contains(1));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<int>, std::vector<int>>();
|
||||
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 0;
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// template<class K> bool contains(const K& x) const;
|
||||
|
||||
#include <cassert>
|
||||
#include <flat_map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <deque>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
// Constraints: The qualified-id Compare::is_transparent is valid and denotes a type.
|
||||
template <class M>
|
||||
concept CanContains = requires(M m, Transparent<int> k) { m.contains(k); };
|
||||
using TransparentMap = std::flat_multimap<int, double, TransparentComparator>;
|
||||
using NonTransparentMap = std::flat_multimap<int, double, NonTransparentComparator>;
|
||||
static_assert(CanContains<TransparentMap>);
|
||||
static_assert(CanContains<const TransparentMap>);
|
||||
static_assert(!CanContains<NonTransparentMap>);
|
||||
static_assert(!CanContains<const NonTransparentMap>);
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
|
||||
|
||||
M m = {{"alpha", 1}, {"beta", 2}, {"beta", 0}, {"epsilon", 3}, {"eta", 4}, {"eta", 1}, {"gamma", 5}};
|
||||
ASSERT_SAME_TYPE(decltype(m.contains(Transparent<std::string>{"abc"})), bool);
|
||||
ASSERT_SAME_TYPE(decltype(std::as_const(m).contains(Transparent<std::string>{"b"})), bool);
|
||||
assert(m.contains(Transparent<std::string>{"alpha"}) == true);
|
||||
assert(m.contains(Transparent<std::string>{"beta"}) == true);
|
||||
assert(m.contains(Transparent<std::string>{"epsilon"}) == true);
|
||||
assert(m.contains(Transparent<std::string>{"eta"}) == true);
|
||||
assert(m.contains(Transparent<std::string>{"gamma"}) == true);
|
||||
assert(m.contains(Transparent<std::string>{"al"}) == false);
|
||||
assert(m.contains(Transparent<std::string>{""}) == false);
|
||||
assert(m.contains(Transparent<std::string>{"g"}) == false);
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<std::string>, std::vector<int>>();
|
||||
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>>>();
|
||||
|
||||
{
|
||||
bool transparent_used = false;
|
||||
TransparentComparator c(transparent_used);
|
||||
std::flat_multimap<int, int, TransparentComparator> m(std::sorted_equivalent, {{1, 1}, {1, 2}, {2, 2}, {3, 3}}, c);
|
||||
assert(!transparent_used);
|
||||
auto b = m.contains(Transparent<int>{3});
|
||||
assert(b);
|
||||
assert(transparent_used);
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// size_type count(const key_type& x) const;
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
|
||||
{
|
||||
using M = std::flat_multimap<Key, Value, std::less<>, KeyContainer, ValueContainer>;
|
||||
M m = {{1, 1}, {2, 2}, {2, 2}, {4, 4}, {4, 1}, {4, 3}, {4, 4}, {5, 5}, {8, 8}};
|
||||
ASSERT_SAME_TYPE(decltype(m.count(0)), size_t);
|
||||
assert(m.count(0) == 0);
|
||||
assert(m.count(1) == 1);
|
||||
assert(m.count(2) == 2);
|
||||
assert(m.count(3) == 0);
|
||||
assert(m.count(4) == 4);
|
||||
assert(m.count(5) == 1);
|
||||
assert(m.count(6) == 0);
|
||||
assert(m.count(7) == 0);
|
||||
assert(std::as_const(m).count(8) == 1);
|
||||
assert(std::as_const(m).count(9) == 0);
|
||||
}
|
||||
{
|
||||
using M = std::flat_multimap<Key, Value, std::greater<int>, KeyContainer, ValueContainer>;
|
||||
M m = {{1, 0}, {2, 0}, {4, 0}, {1, 0}, {1, 2}, {8, 1}, {5, 0}, {8, 0}};
|
||||
ASSERT_SAME_TYPE(decltype(m.count(0)), size_t);
|
||||
assert(m.count(0) == 0);
|
||||
assert(m.count(1) == 3);
|
||||
assert(m.count(2) == 1);
|
||||
assert(m.count(3) == 0);
|
||||
assert(m.count(4) == 1);
|
||||
assert(m.count(5) == 1);
|
||||
assert(m.count(6) == 0);
|
||||
assert(m.count(7) == 0);
|
||||
assert(std::as_const(m).count(8) == 2);
|
||||
assert(std::as_const(m).count(9) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<int>, std::vector<int>>();
|
||||
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 0;
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// template<class K> size_type count(const K& x) const;
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
// Constraints: The qualified-id Compare::is_transparent is valid and denotes a type.
|
||||
template <class M>
|
||||
concept CanCount = requires(M m, Transparent<int> k) { m.count(k); };
|
||||
using TransparentMap = std::flat_multimap<int, double, TransparentComparator>;
|
||||
using NonTransparentMap = std::flat_multimap<int, double, NonTransparentComparator>;
|
||||
static_assert(CanCount<TransparentMap>);
|
||||
static_assert(CanCount<const TransparentMap>);
|
||||
static_assert(!CanCount<NonTransparentMap>);
|
||||
static_assert(!CanCount<const NonTransparentMap>);
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
|
||||
|
||||
M m = {{"alpha", 1},
|
||||
{"beta", 2},
|
||||
{"beta", 2},
|
||||
{"epsilon", 3},
|
||||
{"eta", 4},
|
||||
{"eta", 1},
|
||||
{"eta", 5},
|
||||
{"gamma", 6},
|
||||
{"gamma", 5}};
|
||||
ASSERT_SAME_TYPE(decltype(m.count(Transparent<std::string>{"abc"})), typename M::size_type);
|
||||
ASSERT_SAME_TYPE(decltype(std::as_const(m).count(Transparent<std::string>{"b"})), typename M::size_type);
|
||||
assert(m.count(Transparent<std::string>{"alpha"}) == 1);
|
||||
assert(m.count(Transparent<std::string>{"beta"}) == 2);
|
||||
assert(m.count(Transparent<std::string>{"epsilon"}) == 1);
|
||||
assert(m.count(Transparent<std::string>{"eta"}) == 3);
|
||||
assert(m.count(Transparent<std::string>{"gamma"}) == 2);
|
||||
assert(m.count(Transparent<std::string>{"al"}) == 0);
|
||||
assert(m.count(Transparent<std::string>{""}) == 0);
|
||||
assert(m.count(Transparent<std::string>{"g"}) == 0);
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<std::string>, std::vector<int>>();
|
||||
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>>>();
|
||||
|
||||
{
|
||||
bool transparent_used = false;
|
||||
TransparentComparator c(transparent_used);
|
||||
std::flat_multimap<int, int, TransparentComparator> m(
|
||||
std::sorted_equivalent, {{1, 1}, {2, 2}, {2, 2}, {3, 3}, {3, 3}}, c);
|
||||
assert(!transparent_used);
|
||||
auto n = m.count(Transparent<int>{3});
|
||||
assert(n == 2);
|
||||
assert(transparent_used);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// pair<iterator,iterator> equal_range(const key_type& k);
|
||||
// pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
{
|
||||
using M = std::flat_multimap<Key, Value, std::less<>, KeyContainer, ValueContainer>;
|
||||
using R = std::pair<typename M::iterator, typename M::iterator>;
|
||||
using CR = std::pair<typename M::const_iterator, typename M::const_iterator>;
|
||||
M m = {{1, 'a'}, {1, 'a'}, {1, 'A'}, {2, 'b'}, {4, 'd'}, {5, 'E'}, {5, 'e'}, {8, 'h'}, {8, 'z'}};
|
||||
ASSERT_SAME_TYPE(decltype(m.equal_range(0)), R);
|
||||
ASSERT_SAME_TYPE(decltype(std::as_const(m).equal_range(0)), CR);
|
||||
auto begin = m.begin();
|
||||
assert(m.equal_range(0) == std::pair(begin, begin));
|
||||
assert(m.equal_range(1) == std::pair(begin, begin + 3));
|
||||
assert(m.equal_range(2) == std::pair(begin + 3, begin + 4));
|
||||
assert(m.equal_range(3) == std::pair(begin + 4, begin + 4));
|
||||
assert(m.equal_range(4) == std::pair(begin + 4, begin + 5));
|
||||
assert(m.equal_range(5) == std::pair(begin + 5, begin + 7));
|
||||
assert(m.equal_range(6) == std::pair(begin + 7, begin + 7));
|
||||
assert(m.equal_range(7) == std::pair(begin + 7, begin + 7));
|
||||
assert(std::as_const(m).equal_range(8) == std::pair(m.cbegin() + 7, m.cbegin() + 9));
|
||||
assert(std::as_const(m).equal_range(9) == std::pair(m.cbegin() + 9, m.cbegin() + 9));
|
||||
}
|
||||
|
||||
{
|
||||
using M = std::flat_multimap<Key, Value, std::greater<int>, KeyContainer, ValueContainer>;
|
||||
using R = std::pair<typename M::iterator, typename M::iterator>;
|
||||
using CR = std::pair<typename M::const_iterator, typename M::const_iterator>;
|
||||
M m = {
|
||||
{1, 'a'}, {2, 'b'}, {2, 'b'}, {2, 'c'}, {4, 'a'}, {4, 'b'}, {4, 'c'}, {4, 'd'}, {5, 'e'}, {8, 'a'}, {8, 'h'}};
|
||||
ASSERT_SAME_TYPE(decltype(m.equal_range(0)), R);
|
||||
ASSERT_SAME_TYPE(decltype(std::as_const(m).equal_range(0)), CR);
|
||||
auto begin = m.begin();
|
||||
assert(m.equal_range(0) == std::pair(begin + 11, begin + 11));
|
||||
assert(m.equal_range(1) == std::pair(begin + 10, begin + 11));
|
||||
assert(m.equal_range(2) == std::pair(begin + 7, begin + 10));
|
||||
assert(m.equal_range(3) == std::pair(begin + 7, begin + 7));
|
||||
assert(m.equal_range(4) == std::pair(begin + 3, begin + 7));
|
||||
assert(m.equal_range(5) == std::pair(begin + 2, begin + 3));
|
||||
assert(m.equal_range(6) == std::pair(begin + 2, begin + 2));
|
||||
assert(m.equal_range(7) == std::pair(begin + 2, begin + 2));
|
||||
assert(std::as_const(m).equal_range(8) == std::pair(m.cbegin(), m.cbegin() + 2));
|
||||
assert(std::as_const(m).equal_range(9) == std::pair(m.cbegin(), m.cbegin()));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<int>, std::vector<char>>();
|
||||
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 0;
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// template<class K> pair<iterator,iterator> equal_range(const K& x);
|
||||
// template<class K> pair<const_iterator,const_iterator> equal_range(const K& x) const;
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
// Constraints: The qualified-id Compare::is_transparent is valid and denotes a type.
|
||||
template <class M>
|
||||
concept CanEqualRange = requires(M m, Transparent<int> k) { m.equal_range(k); };
|
||||
using TransparentMap = std::flat_multimap<int, double, TransparentComparator>;
|
||||
using NonTransparentMap = std::flat_multimap<int, double, NonTransparentComparator>;
|
||||
static_assert(CanEqualRange<TransparentMap>);
|
||||
static_assert(CanEqualRange<const TransparentMap>);
|
||||
static_assert(!CanEqualRange<NonTransparentMap>);
|
||||
static_assert(!CanEqualRange<const NonTransparentMap>);
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
|
||||
|
||||
using R = std::pair<typename M::iterator, typename M::iterator>;
|
||||
using CR = std::pair<typename M::const_iterator, typename M::const_iterator>;
|
||||
M m = {{"alpha", 1},
|
||||
{"alpha", 1},
|
||||
{"alpha", 3},
|
||||
{"beta", 2},
|
||||
{"epsilon", 3},
|
||||
{"epsilon", 0},
|
||||
{"eta", 4},
|
||||
{"gamma", 5},
|
||||
{"gamma", 1}};
|
||||
const auto& cm = m;
|
||||
ASSERT_SAME_TYPE(decltype(m.equal_range(Transparent<std::string>{"abc"})), R);
|
||||
ASSERT_SAME_TYPE(decltype(std::as_const(m).equal_range(Transparent<std::string>{"b"})), CR);
|
||||
|
||||
auto test_found = [&](auto&& map, const auto& expected_key, std::initializer_list<Value> expected_values) {
|
||||
auto [first, last] = map.equal_range(Transparent<std::string>{expected_key});
|
||||
auto expected_range =
|
||||
expected_values | std::views::transform([&](auto&& val) { return std::pair(expected_key, val); });
|
||||
assert(std::ranges::equal(std::ranges::subrange(first, last), expected_range));
|
||||
};
|
||||
|
||||
auto test_not_found = [&](auto&& map, const std::string& expected_key, long expected_offset) {
|
||||
auto [first, last] = map.equal_range(Transparent<std::string>{expected_key});
|
||||
assert(first == last);
|
||||
assert(first - m.begin() == expected_offset);
|
||||
};
|
||||
|
||||
test_found(m, "alpha", {1, 1, 3});
|
||||
test_found(m, "beta", {2});
|
||||
test_found(m, "epsilon", {3, 0});
|
||||
test_found(m, "eta", {4});
|
||||
test_found(m, "gamma", {5, 1});
|
||||
test_found(cm, "alpha", {1, 1, 3});
|
||||
test_found(cm, "beta", {2});
|
||||
test_found(cm, "epsilon", {3, 0});
|
||||
test_found(cm, "eta", {4});
|
||||
test_found(cm, "gamma", {5, 1});
|
||||
|
||||
test_not_found(m, "charlie", 4);
|
||||
test_not_found(m, "aaa", 0);
|
||||
test_not_found(m, "zzz", 9);
|
||||
test_not_found(cm, "charlie", 4);
|
||||
test_not_found(cm, "aaa", 0);
|
||||
test_not_found(cm, "zzz", 9);
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<std::string>, std::vector<int>>();
|
||||
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>>>();
|
||||
|
||||
{
|
||||
bool transparent_used = false;
|
||||
TransparentComparator c(transparent_used);
|
||||
std::flat_multimap<int, int, TransparentComparator> m(std::sorted_equivalent, {{1, 1}, {2, 2}, {3, 1}, {3, 3}}, c);
|
||||
assert(!transparent_used);
|
||||
auto p = m.equal_range(Transparent<int>{3});
|
||||
assert(p.first == m.begin() + 2);
|
||||
assert(p.second == m.end());
|
||||
assert(transparent_used);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// iterator find(const key_type& k);
|
||||
// const_iterator find(const key_type& k) const;
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
|
||||
M m = {{1, 'a'}, {1, 'a'}, {1, 'b'}, {2, 'c'}, {2, 'b'}, {4, 'a'}, {4, 'd'}, {5, 'e'}, {8, 'a'}, {8, 'h'}};
|
||||
ASSERT_SAME_TYPE(decltype(m.find(0)), typename M::iterator);
|
||||
ASSERT_SAME_TYPE(decltype(std::as_const(m).find(0)), typename M::const_iterator);
|
||||
assert(m.find(0) == m.end());
|
||||
assert(m.find(1) == m.begin());
|
||||
assert(m.find(2) == m.begin() + 3);
|
||||
assert(m.find(3) == m.end());
|
||||
assert(m.find(4) == m.begin() + 5);
|
||||
assert(m.find(5) == m.begin() + 7);
|
||||
assert(m.find(6) == m.end());
|
||||
assert(m.find(7) == m.end());
|
||||
assert(std::as_const(m).find(8) == m.begin() + 8);
|
||||
assert(std::as_const(m).find(9) == m.end());
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<int>, std::vector<char>>();
|
||||
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 0;
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// template<class K> iterator find(const K& x);
|
||||
// template<class K> const_iterator find(const K& x) const;
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
// Constraints: The qualified-id Compare::is_transparent is valid and denotes a type.
|
||||
template <class M>
|
||||
concept CanFind = requires(M m, Transparent<int> k) { m.find(k); };
|
||||
using TransparentMap = std::flat_multimap<int, double, TransparentComparator>;
|
||||
using NonTransparentMap = std::flat_multimap<int, double, NonTransparentComparator>;
|
||||
static_assert(CanFind<TransparentMap>);
|
||||
static_assert(CanFind<const TransparentMap>);
|
||||
static_assert(!CanFind<NonTransparentMap>);
|
||||
static_assert(!CanFind<const NonTransparentMap>);
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
|
||||
|
||||
M m = {{"alpha", 1},
|
||||
{"beta", 2},
|
||||
{"beta", 0},
|
||||
{"beta", 1},
|
||||
{"beta", 2},
|
||||
{"epsilon", 3},
|
||||
{"epsilon", 1},
|
||||
{"eta", 4},
|
||||
{"gamma", 6},
|
||||
{"gamma", 5}};
|
||||
const auto& cm = m;
|
||||
ASSERT_SAME_TYPE(decltype(m.find(Transparent<std::string>{"abc"})), typename M::iterator);
|
||||
ASSERT_SAME_TYPE(decltype(std::as_const(m).find(Transparent<std::string>{"b"})), typename M::const_iterator);
|
||||
|
||||
auto test_find = [&](auto&& map, const std::string& expected_key, long expected_offset) {
|
||||
auto iter = map.find(Transparent<std::string>{expected_key});
|
||||
assert(iter - map.begin() == expected_offset);
|
||||
};
|
||||
|
||||
test_find(m, "alpha", 0);
|
||||
test_find(m, "beta", 1);
|
||||
test_find(m, "epsilon", 5);
|
||||
test_find(m, "eta", 7);
|
||||
test_find(m, "gamma", 8);
|
||||
test_find(m, "charlie", 10);
|
||||
test_find(m, "aaa", 10);
|
||||
test_find(m, "zzz", 10);
|
||||
test_find(cm, "alpha", 0);
|
||||
test_find(cm, "beta", 1);
|
||||
test_find(cm, "epsilon", 5);
|
||||
test_find(cm, "eta", 7);
|
||||
test_find(cm, "gamma", 8);
|
||||
test_find(cm, "charlie", 10);
|
||||
test_find(cm, "aaa", 10);
|
||||
test_find(cm, "zzz", 10);
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<std::string>, std::vector<int>>();
|
||||
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>>>();
|
||||
|
||||
{
|
||||
bool transparent_used = false;
|
||||
TransparentComparator c(transparent_used);
|
||||
std::flat_multimap<int, int, TransparentComparator> m(std::sorted_equivalent, {{1, 1}, {2, 2}, {3, 3}, {3, 3}}, c);
|
||||
assert(!transparent_used);
|
||||
auto it = m.find(Transparent<int>{3});
|
||||
assert(it != m.end());
|
||||
assert(transparent_used);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// iterator lower_bound(const key_type& k);
|
||||
// const_iterator lower_bound(const key_type& k) const;
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
{
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
M m = {{1, 'a'}, {2, 'a'}, {2, 'c'}, {2, 'b'}, {4, 'd'}, {5, 'a'}, {5, 'e'}, {8, 'h'}, {8, 'a'}};
|
||||
ASSERT_SAME_TYPE(decltype(m.lower_bound(0)), typename M::iterator);
|
||||
ASSERT_SAME_TYPE(decltype(std::as_const(m).lower_bound(0)), typename M::const_iterator);
|
||||
assert(m.lower_bound(0) == m.begin());
|
||||
assert(m.lower_bound(1) == m.begin());
|
||||
assert(m.lower_bound(2) == m.begin() + 1);
|
||||
assert(m.lower_bound(3) == m.begin() + 4);
|
||||
assert(m.lower_bound(4) == m.begin() + 4);
|
||||
assert(m.lower_bound(5) == m.begin() + 5);
|
||||
assert(m.lower_bound(6) == m.begin() + 7);
|
||||
assert(m.lower_bound(7) == m.begin() + 7);
|
||||
assert(std::as_const(m).lower_bound(8) == m.begin() + 7);
|
||||
assert(std::as_const(m).lower_bound(9) == m.end());
|
||||
}
|
||||
{
|
||||
using M = std::flat_multimap<Key, Value, std::greater<Key>, KeyContainer, ValueContainer>;
|
||||
M m = {{1, 'a'}, {1, 'b'}, {2, 'b'}, {4, 'd'}, {4, 'a'}, {4, 'e'}, {5, 'e'}, {8, 'a'}, {8, 'h'}};
|
||||
ASSERT_SAME_TYPE(decltype(m.lower_bound(0)), typename M::iterator);
|
||||
ASSERT_SAME_TYPE(decltype(std::as_const(m).lower_bound(0)), typename M::const_iterator);
|
||||
assert(m.lower_bound(0) == m.end());
|
||||
assert(m.lower_bound(1) == m.begin() + 7);
|
||||
assert(m.lower_bound(2) == m.begin() + 6);
|
||||
assert(m.lower_bound(3) == m.begin() + 6);
|
||||
assert(m.lower_bound(4) == m.begin() + 3);
|
||||
assert(m.lower_bound(5) == m.begin() + 2);
|
||||
assert(m.lower_bound(6) == m.begin() + 2);
|
||||
assert(m.lower_bound(7) == m.begin() + 2);
|
||||
assert(std::as_const(m).lower_bound(8) == m.begin());
|
||||
assert(std::as_const(m).lower_bound(9) == m.begin());
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<int>, std::vector<char>>();
|
||||
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 0;
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// template<class K> iterator lower_bound(const K& x);
|
||||
// template<class K> const_iterator lower_bound(const K& x) const;
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
// Constraints: The qualified-id Compare::is_transparent is valid and denotes a type.
|
||||
template <class M>
|
||||
concept CanLowerBound = requires(M m, Transparent<int> k) { m.lower_bound(k); };
|
||||
using TransparentMap = std::flat_multimap<int, double, TransparentComparator>;
|
||||
using NonTransparentMap = std::flat_multimap<int, double, NonTransparentComparator>;
|
||||
static_assert(CanLowerBound<TransparentMap>);
|
||||
static_assert(CanLowerBound<const TransparentMap>);
|
||||
static_assert(!CanLowerBound<NonTransparentMap>);
|
||||
static_assert(!CanLowerBound<const NonTransparentMap>);
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
|
||||
|
||||
M m = {{"alpha", 1},
|
||||
{"alpha", 2},
|
||||
{"alpha", 3},
|
||||
{"beta", 2},
|
||||
{"epsilon", 3},
|
||||
{"epsilon", 4},
|
||||
{"eta", 4},
|
||||
{"gamma", 5},
|
||||
{"gamma", 5},
|
||||
{"gamma", 5},
|
||||
{"gamma", 5}};
|
||||
const auto& cm = m;
|
||||
ASSERT_SAME_TYPE(decltype(m.lower_bound(Transparent<std::string>{"abc"})), typename M::iterator);
|
||||
ASSERT_SAME_TYPE(decltype(std::as_const(m).lower_bound(Transparent<std::string>{"b"})), typename M::const_iterator);
|
||||
|
||||
auto test_lower_bound = [&](auto&& map, const std::string& expected_key, long expected_offset) {
|
||||
auto iter = map.lower_bound(Transparent<std::string>{expected_key});
|
||||
assert(iter - map.begin() == expected_offset);
|
||||
};
|
||||
|
||||
test_lower_bound(m, "abc", 0);
|
||||
test_lower_bound(m, "alpha", 0);
|
||||
test_lower_bound(m, "beta", 3);
|
||||
test_lower_bound(m, "bets", 4);
|
||||
test_lower_bound(m, "charlie", 4);
|
||||
test_lower_bound(m, "echo", 4);
|
||||
test_lower_bound(m, "epsilon", 4);
|
||||
test_lower_bound(m, "eta", 6);
|
||||
test_lower_bound(m, "gamma", 7);
|
||||
test_lower_bound(m, "golf", 11);
|
||||
test_lower_bound(m, "zzz", 11);
|
||||
|
||||
test_lower_bound(cm, "abc", 0);
|
||||
test_lower_bound(cm, "alpha", 0);
|
||||
test_lower_bound(cm, "beta", 3);
|
||||
test_lower_bound(cm, "bets", 4);
|
||||
test_lower_bound(cm, "charlie", 4);
|
||||
test_lower_bound(cm, "echo", 4);
|
||||
test_lower_bound(cm, "epsilon", 4);
|
||||
test_lower_bound(cm, "eta", 6);
|
||||
test_lower_bound(cm, "gamma", 7);
|
||||
test_lower_bound(cm, "golf", 11);
|
||||
test_lower_bound(cm, "zzz", 11);
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<std::string>, std::vector<int>>();
|
||||
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>>>();
|
||||
|
||||
{
|
||||
bool transparent_used = false;
|
||||
TransparentComparator c(transparent_used);
|
||||
std::flat_multimap<int, int, TransparentComparator> m(std::sorted_equivalent, {{1, 1}, {2, 2}, {3, 3}}, c);
|
||||
assert(!transparent_used);
|
||||
auto it = m.lower_bound(Transparent<int>{3});
|
||||
assert(it != m.end());
|
||||
assert(transparent_used);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// iterator upper_bound(const key_type& k);
|
||||
// const_iterator upper_bound(const key_type& k) const;
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
{
|
||||
using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
|
||||
M m = {
|
||||
{1, 'a'}, {2, 'b'}, {4, 'd'}, {4, 'e'}, {4, 'a'}, {4, 'b'}, {5, 'e'}, {5, 'a'}, {8, 'a'}, {8, 'b'}, {8, 'h'}};
|
||||
ASSERT_SAME_TYPE(decltype(m.upper_bound(0)), typename M::iterator);
|
||||
ASSERT_SAME_TYPE(decltype(std::as_const(m).upper_bound(0)), typename M::const_iterator);
|
||||
assert(m.upper_bound(0) == m.begin());
|
||||
assert(m.upper_bound(1) == m.begin() + 1);
|
||||
assert(m.upper_bound(2) == m.begin() + 2);
|
||||
assert(m.upper_bound(3) == m.begin() + 2);
|
||||
assert(m.upper_bound(4) == m.begin() + 6);
|
||||
assert(m.upper_bound(5) == m.begin() + 8);
|
||||
assert(m.upper_bound(6) == m.begin() + 8);
|
||||
assert(std::as_const(m).upper_bound(7) == m.begin() + 8);
|
||||
assert(std::as_const(m).upper_bound(8) == m.end());
|
||||
assert(std::as_const(m).upper_bound(9) == m.end());
|
||||
}
|
||||
|
||||
{
|
||||
using M = std::flat_multimap<Key, Value, std::greater<Key>, KeyContainer, ValueContainer>;
|
||||
M m = {
|
||||
{1, 'a'}, {2, 'b'}, {4, 'd'}, {4, 'e'}, {4, 'a'}, {4, 'b'}, {5, 'e'}, {5, 'a'}, {8, 'a'}, {8, 'b'}, {8, 'h'}};
|
||||
ASSERT_SAME_TYPE(decltype(m.upper_bound(0)), typename M::iterator);
|
||||
ASSERT_SAME_TYPE(decltype(std::as_const(m).upper_bound(0)), typename M::const_iterator);
|
||||
assert(m.upper_bound(0) == m.end());
|
||||
assert(m.upper_bound(1) == m.end());
|
||||
assert(m.upper_bound(2) == m.begin() + 10);
|
||||
assert(m.upper_bound(3) == m.begin() + 9);
|
||||
assert(m.upper_bound(4) == m.begin() + 9);
|
||||
assert(m.upper_bound(5) == m.begin() + 5);
|
||||
assert(m.upper_bound(6) == m.begin() + 3);
|
||||
assert(m.upper_bound(7) == m.begin() + 3);
|
||||
assert(std::as_const(m).upper_bound(8) == m.begin() + 3);
|
||||
assert(std::as_const(m).upper_bound(9) == m.begin());
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<int>, std::vector<char>>();
|
||||
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 0;
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <flat_map>
|
||||
|
||||
// class flat_multimap
|
||||
|
||||
// template<class K> iterator upper_bound(const K& x);
|
||||
// template<class K> const_iterator upper_bound(const K& x) const;
|
||||
|
||||
#include <cassert>
|
||||
#include <deque>
|
||||
#include <flat_map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "MinSequenceContainer.h"
|
||||
#include "../helpers.h"
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
||||
// Constraints: The qualified-id Compare::is_transparent is valid and denotes a type.
|
||||
template <class M>
|
||||
concept CanUpperBound = requires(M m, Transparent<int> k) { m.upper_bound(k); };
|
||||
using TransparentMap = std::flat_multimap<int, double, TransparentComparator>;
|
||||
using NonTransparentMap = std::flat_multimap<int, double, NonTransparentComparator>;
|
||||
static_assert(CanUpperBound<TransparentMap>);
|
||||
static_assert(CanUpperBound<const TransparentMap>);
|
||||
static_assert(!CanUpperBound<NonTransparentMap>);
|
||||
static_assert(!CanUpperBound<const NonTransparentMap>);
|
||||
|
||||
template <class KeyContainer, class ValueContainer>
|
||||
void test() {
|
||||
using Key = typename KeyContainer::value_type;
|
||||
using Value = typename ValueContainer::value_type;
|
||||
using M = std::flat_multimap<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
|
||||
|
||||
M m = {{"alpha", 1},
|
||||
{"alpha", 2},
|
||||
{"alpha", 3},
|
||||
{"beta", 2},
|
||||
{"epsilon", 3},
|
||||
{"epsilon", 4},
|
||||
{"eta", 4},
|
||||
{"gamma", 5},
|
||||
{"gamma", 5},
|
||||
{"gamma", 5},
|
||||
{"gamma", 5}};
|
||||
const auto& cm = m;
|
||||
ASSERT_SAME_TYPE(decltype(m.lower_bound(Transparent<std::string>{"abc"})), typename M::iterator);
|
||||
ASSERT_SAME_TYPE(decltype(std::as_const(m).lower_bound(Transparent<std::string>{"b"})), typename M::const_iterator);
|
||||
|
||||
auto test_upper_bound = [&](auto&& map, const std::string& expected_key, long expected_offset) {
|
||||
auto iter = map.upper_bound(Transparent<std::string>{expected_key});
|
||||
assert(iter - map.begin() == expected_offset);
|
||||
};
|
||||
|
||||
test_upper_bound(m, "abc", 0);
|
||||
test_upper_bound(m, "alpha", 3);
|
||||
test_upper_bound(m, "beta", 4);
|
||||
test_upper_bound(m, "bets", 4);
|
||||
test_upper_bound(m, "charlie", 4);
|
||||
test_upper_bound(m, "echo", 4);
|
||||
test_upper_bound(m, "epsilon", 6);
|
||||
test_upper_bound(m, "eta", 7);
|
||||
test_upper_bound(m, "gamma", 11);
|
||||
test_upper_bound(m, "golf", 11);
|
||||
test_upper_bound(m, "zzz", 11);
|
||||
|
||||
test_upper_bound(cm, "abc", 0);
|
||||
test_upper_bound(cm, "alpha", 3);
|
||||
test_upper_bound(cm, "beta", 4);
|
||||
test_upper_bound(cm, "bets", 4);
|
||||
test_upper_bound(cm, "charlie", 4);
|
||||
test_upper_bound(cm, "echo", 4);
|
||||
test_upper_bound(cm, "epsilon", 6);
|
||||
test_upper_bound(cm, "eta", 7);
|
||||
test_upper_bound(cm, "gamma", 11);
|
||||
test_upper_bound(cm, "golf", 11);
|
||||
test_upper_bound(cm, "zzz", 11);
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::vector<std::string>, std::vector<int>>();
|
||||
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>>>();
|
||||
{
|
||||
bool transparent_used = false;
|
||||
TransparentComparator c(transparent_used);
|
||||
std::flat_multimap<int, int, TransparentComparator> m(std::sorted_equivalent, {{1, 1}, {2, 2}, {2, 2}, {3, 3}}, c);
|
||||
assert(!transparent_used);
|
||||
auto it = m.upper_bound(Transparent<int>{2});
|
||||
assert(it == m.begin() + 3);
|
||||
assert(transparent_used);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user