Skip to content

Commit 253c1b9

Browse files
committed
[libc++] Do not call in flat containers if underlying container is user defined
1 parent 6f7268e commit 253c1b9

File tree

18 files changed

+71
-6
lines changed

18 files changed

+71
-6
lines changed

libcxx/include/__flat_map/flat_map.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,11 +1017,11 @@ class flat_map {
10171017
}
10181018

10191019
_LIBCPP_HIDE_FROM_ABI void __reserve(size_t __size) {
1020-
if constexpr (requires { __containers_.keys.reserve(__size); }) {
1020+
if constexpr (__container_traits<_KeyContainer>::__reservable) {
10211021
__containers_.keys.reserve(__size);
10221022
}
10231023

1024-
if constexpr (requires { __containers_.values.reserve(__size); }) {
1024+
if constexpr (__container_traits<_MappedContainer>::__reservable) {
10251025
__containers_.values.reserve(__size);
10261026
}
10271027
}

libcxx/include/__flat_map/flat_multimap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,11 +826,11 @@ class flat_multimap {
826826
}
827827

828828
_LIBCPP_HIDE_FROM_ABI void __reserve(size_t __size) {
829-
if constexpr (requires { __containers_.keys.reserve(__size); }) {
829+
if constexpr (__container_traits<_KeyContainer>::__reservable) {
830830
__containers_.keys.reserve(__size);
831831
}
832832

833-
if constexpr (requires { __containers_.values.reserve(__size); }) {
833+
if constexpr (__container_traits<_MappedContainer>::__reservable) {
834834
__containers_.values.reserve(__size);
835835
}
836836
}

libcxx/include/__flat_set/flat_multiset.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ class flat_multiset {
667667
}
668668

669669
_LIBCPP_HIDE_FROM_ABI void __reserve(size_t __size) {
670-
if constexpr (requires { __keys_.reserve(__size); }) {
670+
if constexpr (__container_traits<_KeyContainer>::__reservable) {
671671
__keys_.reserve(__size);
672672
}
673673
}

libcxx/include/__flat_set/flat_set.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ class flat_set {
699699
}
700700

701701
_LIBCPP_HIDE_FROM_ABI void __reserve(size_t __size) {
702-
if constexpr (requires { __keys_.reserve(__size); }) {
702+
if constexpr (__container_traits<_KeyContainer>::__reservable) {
703703
__keys_.reserve(__size);
704704
}
705705
}

libcxx/include/__type_traits/container_traits.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ struct __container_traits {
3636
// `insert(...)` or `emplace(...)` has strong exception guarantee, that is, if the function
3737
// exits via an exception, the original container is unaffected
3838
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = false;
39+
40+
static _LIBCPP_CONSTEXPR const bool __reservable = false;
3941
};
4042

4143
_LIBCPP_END_NAMESPACE_STD

libcxx/include/__vector/container_traits.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ struct __container_traits<vector<_Tp, _Allocator> > {
3232
// the effects are unspecified.
3333
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
3434
is_nothrow_move_constructible<_Tp>::value || __is_cpp17_copy_insertable_v<_Allocator>;
35+
36+
static _LIBCPP_CONSTEXPR const bool __reservable = true;
3537
};
3638

3739
_LIBCPP_END_NAMESPACE_STD

libcxx/include/deque

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,6 +2631,8 @@ struct __container_traits<deque<_Tp, _Allocator> > {
26312631
// non-Cpp17CopyInsertable T, the effects are unspecified.
26322632
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
26332633
is_nothrow_move_constructible<_Tp>::value || __is_cpp17_copy_insertable_v<_Allocator>;
2634+
2635+
static _LIBCPP_CONSTEXPR const bool __reservable = false;
26342636
};
26352637

26362638
_LIBCPP_END_NAMESPACE_STD

libcxx/include/forward_list

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,8 @@ struct __container_traits<forward_list<_Tp, _Allocator> > {
15671567
// - If an exception is thrown by an insert() or emplace() function while inserting a single element, that
15681568
// function has no effects.
15691569
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
1570+
1571+
static _LIBCPP_CONSTEXPR const bool __reservable = false;
15701572
};
15711573

15721574
_LIBCPP_END_NAMESPACE_STD

libcxx/include/list

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,8 @@ struct __container_traits<list<_Tp, _Allocator> > {
17181718
// - If an exception is thrown by an insert() or emplace() function while inserting a single element, that
17191719
// function has no effects.
17201720
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
1721+
1722+
static _LIBCPP_CONSTEXPR const bool __reservable = false;
17211723
};
17221724

17231725
_LIBCPP_END_NAMESPACE_STD

libcxx/include/map

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,8 @@ struct __container_traits<map<_Key, _Tp, _Compare, _Allocator> > {
15601560
// For associative containers, if an exception is thrown by any operation from within
15611561
// an insert or emplace function inserting a single element, the insertion has no effect.
15621562
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
1563+
1564+
static _LIBCPP_CONSTEXPR const bool __reservable = false;
15631565
};
15641566

15651567
template <class _Key, class _Tp, class _Compare, class _Allocator>
@@ -2083,6 +2085,8 @@ struct __container_traits<multimap<_Key, _Tp, _Compare, _Allocator> > {
20832085
// For associative containers, if an exception is thrown by any operation from within
20842086
// an insert or emplace function inserting a single element, the insertion has no effect.
20852087
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
2088+
2089+
static _LIBCPP_CONSTEXPR const bool __reservable = false;
20862090
};
20872091

20882092
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)