Skip to content

Commit 285a1e5

Browse files
committed
update
1 parent fcbaf8b commit 285a1e5

23 files changed

+2994
-4
lines changed

libcxx/include/__flat_set/flat_multiset.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,12 @@ class flat_multiset {
682682
return std::make_pair(__iter(__key_first), __iter(__key_last));
683683
}
684684

685+
_LIBCPP_HIDE_FROM_ABI void __reserve(size_t __size) {
686+
if constexpr (requires { __keys_.reserve(__size); }) {
687+
__keys_.reserve(__size);
688+
}
689+
}
690+
685691
template <class _Key2, class _Compare2, class _KeyContainer2, class _Predicate>
686692
friend typename flat_multiset<_Key2, _Compare2, _KeyContainer2>::size_type
687693
erase_if(flat_multiset<_Key2, _Compare2, _KeyContainer2>&, _Predicate);
@@ -750,16 +756,16 @@ flat_multiset(_InputIterator, _InputIterator, _Compare = _Compare())
750756
template <class _InputIterator, class _Compare = less<__iter_value_type<_InputIterator>>>
751757
requires(__has_input_iterator_category<_InputIterator>::value && !__is_allocator<_Compare>::value)
752758
flat_multiset(sorted_equivalent_t, _InputIterator, _InputIterator, _Compare = _Compare())
753-
-> flat_multiset<__iter_value_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare>;
759+
-> flat_multiset<__iter_value_type<_InputIterator>, _Compare>;
754760

755761
template <ranges::input_range _Range,
756-
class _Compare = less<__iter_value_type<_Range>>,
757-
class _Allocator = allocator<byte>,
762+
class _Compare = less<ranges::range_value_t<_Range>>,
763+
class _Allocator = allocator<ranges::range_value_t<_Range>>,
758764
class = __enable_if_t<!__is_allocator<_Compare>::value && __is_allocator<_Allocator>::value>>
759765
flat_multiset(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator()) -> flat_multiset<
760766
ranges::range_value_t<_Range>,
761767
_Compare,
762-
vector<ranges::range_value_t<_Range>, __allocator_traits_rebind_t<_Allocator, __range_key_type<_Range>>>>;
768+
vector<ranges::range_value_t<_Range>, __allocator_traits_rebind_t<_Allocator, ranges::range_value_t<_Range>>>>;
763769

764770
template <ranges::input_range _Range, class _Allocator, class = __enable_if_t<__is_allocator<_Allocator>::value>>
765771
flat_multiset(from_range_t, _Range&&, _Allocator) -> flat_multiset<
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
11+
// <flat_set>
12+
13+
// template<class Allocator>
14+
// explicit flat_multiset(const Allocator& a);
15+
16+
#include <cassert>
17+
#include <flat_set>
18+
#include <functional>
19+
#include <vector>
20+
21+
#include "test_macros.h"
22+
#include "test_allocator.h"
23+
#include "../../../test_compare.h"
24+
25+
void test() {
26+
{
27+
// The constructors in this subclause shall not participate in overload
28+
// resolution unless uses_allocator_v<container_type, Alloc> is true
29+
30+
using C = test_less<int>;
31+
using A1 = test_allocator<int>;
32+
using A2 = other_allocator<int>;
33+
using V1 = std::vector<int, A1>;
34+
using V2 = std::vector<int, A2>;
35+
using M1 = std::flat_multiset<int, C, V1>;
36+
using M2 = std::flat_multiset<int, C, V2>;
37+
static_assert(std::is_constructible_v<M1, const A1&>);
38+
static_assert(std::is_constructible_v<M2, const A2&>);
39+
static_assert(!std::is_constructible_v<M1, const A2&>);
40+
static_assert(!std::is_constructible_v<M2, const A1&>);
41+
}
42+
{
43+
// explicit
44+
using M = std::flat_multiset<int, std::less<int>, std::vector<int, test_allocator<int>>>;
45+
46+
static_assert(std::is_constructible_v<M, test_allocator<int>>);
47+
static_assert(!std::is_convertible_v<test_allocator<int>, M>);
48+
}
49+
{
50+
using A = test_allocator<short>;
51+
using M = std::flat_multiset<int, std::less<int>, std::vector<int, test_allocator<int>>>;
52+
M m(A(0, 5));
53+
assert(m.empty());
54+
assert(m.begin() == m.end());
55+
assert(std::move(m).extract().get_allocator().get_id() == 5);
56+
}
57+
}
58+
59+
int main(int, char**) {
60+
test();
61+
62+
return 0;
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
11+
// <flat_set>
12+
13+
// flat_multiset& operator=(initializer_list<value_type> il);
14+
15+
#include <algorithm>
16+
#include <cassert>
17+
#include <deque>
18+
#include <flat_set>
19+
#include <functional>
20+
#include <ranges>
21+
#include <vector>
22+
23+
#include "MinSequenceContainer.h"
24+
#include "test_macros.h"
25+
#include "min_allocator.h"
26+
#include "test_allocator.h"
27+
28+
template <class KeyContainer>
29+
void test() {
30+
using Key = typename KeyContainer::value_type;
31+
using M = std::flat_multiset<Key, std::less<Key>, KeyContainer>;
32+
{
33+
M m = {8, 10};
34+
assert(m.size() == 2);
35+
m = {3, 1, 2, 2, 3, 4, 3, 5, 6, 5};
36+
int expected[] = {1, 2, 2, 3, 3, 3, 4, 5, 5, 6};
37+
assert(std::ranges::equal(m, expected));
38+
}
39+
{
40+
M m = {10, 8};
41+
assert(m.size() == 2);
42+
m = {3};
43+
double expected[] = {3};
44+
assert(std::ranges::equal(m, expected));
45+
}
46+
}
47+
48+
void test() {
49+
test<std::vector<int>>();
50+
test<std::vector<double>>();
51+
test<std::deque<int>>();
52+
test<MinSequenceContainer<int>>();
53+
test<std::vector<int, min_allocator<int>>>();
54+
}
55+
56+
int main(int, char**) {
57+
test();
58+
59+
return 0;
60+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
11+
// <flat_set>
12+
13+
// explicit flat_multiset(const key_compare& comp);
14+
// template <class Alloc>
15+
// flat_multiset(const key_compare& comp, const Alloc& a);
16+
17+
#include <deque>
18+
#include <flat_set>
19+
#include <functional>
20+
#include <type_traits>
21+
#include <vector>
22+
23+
#include "test_macros.h"
24+
#include "../../../test_compare.h"
25+
#include "test_allocator.h"
26+
27+
void test() {
28+
{
29+
// The constructors in this subclause shall not participate in overload
30+
// resolution unless uses_allocator_v<container_type, Alloc> is true
31+
32+
using C = test_less<int>;
33+
using A1 = test_allocator<int>;
34+
using A2 = other_allocator<int>;
35+
using V1 = std::vector<int, A1>;
36+
using V2 = std::vector<int, A2>;
37+
using M1 = std::flat_multiset<int, C, V1>;
38+
using M2 = std::flat_multiset<int, C, V2>;
39+
static_assert(std::is_constructible_v<M1, const C&, const A1&>);
40+
static_assert(std::is_constructible_v<M2, const C&, const A2&>);
41+
static_assert(!std::is_constructible_v<M1, const C&, const A2&>);
42+
static_assert(!std::is_constructible_v<M2, const C&, const A1&>);
43+
}
44+
{
45+
using C = test_less<int>;
46+
auto m = std::flat_multiset<int, C>(C(3));
47+
assert(m.empty());
48+
assert(m.begin() == m.end());
49+
assert(m.key_comp() == C(3));
50+
}
51+
{
52+
// The one-argument ctor is explicit.
53+
using C = test_less<int>;
54+
static_assert(std::is_constructible_v<std::flat_multiset<int, C>, C>);
55+
static_assert(!std::is_convertible_v<C, std::flat_multiset<int, C>>);
56+
57+
static_assert(std::is_constructible_v<std::flat_multiset<int>, std::less<int>>);
58+
static_assert(!std::is_convertible_v<std::less<int>, std::flat_multiset<int>>);
59+
}
60+
{
61+
using C = test_less<int>;
62+
using A1 = test_allocator<int>;
63+
auto m = std::flat_multiset<int, C, std::vector<int, A1>>(C(4), A1(5));
64+
assert(m.empty());
65+
assert(m.begin() == m.end());
66+
assert(m.key_comp() == C(4));
67+
assert(std::move(m).extract().get_allocator() == A1(5));
68+
}
69+
{
70+
// explicit(false)
71+
using C = test_less<int>;
72+
using A1 = test_allocator<int>;
73+
std::flat_multiset<int, C, std::deque<int, A1>> m = {C(4), A1(5)};
74+
assert(m.empty());
75+
assert(m.begin() == m.end());
76+
assert(m.key_comp() == C(4));
77+
assert(std::move(m).extract().get_allocator() == A1(5));
78+
}
79+
}
80+
81+
int main(int, char**) {
82+
test();
83+
84+
return 0;
85+
}

0 commit comments

Comments
 (0)