Skip to content

Commit c99bc9f

Browse files
committed
rebase and address comments
1 parent f3c685c commit c99bc9f

File tree

10 files changed

+140
-138
lines changed

10 files changed

+140
-138
lines changed

libcxx/include/__type_traits/container_traits.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,29 @@
66
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
77
//
88
//===----------------------------------------------------------------------===//
9+
910
#ifndef _LIBCPP___TYPE_TRAITS_CONTAINER_TRAITS_H
1011
#define _LIBCPP___TYPE_TRAITS_CONTAINER_TRAITS_H
1112

1213
#include <__config>
13-
#include <__type_traits/integral_constant.h>
1414

1515
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1616
# pragma GCC system_header
1717
#endif
1818

1919
_LIBCPP_BEGIN_NAMESPACE_STD
2020

21-
template <class _Tp>
21+
// __container_traits is a general purpose struct contains traits of containers' different operations.
22+
// It currently only has one trait: `__emplacement_has_strong_exception_safety_guarantee`, but it's
23+
// intended to be extended in the future.
24+
// If a container does not support an operation. For example, `std::array` does not support `insert`
25+
// or `emplace`, the trait of that operation will return false.
26+
template <class _Container>
2227
struct __container_traits {
23-
using __emplacement_has_strong_exception_safety_guarantee = false_type;
28+
// A trait that tells whether a single element insertion/emplacement via member function
29+
// `insert(...)` or `emplace(...)` has strong exception guarantee, that is, if the function
30+
// exits via an exception, the original container is unaffected
31+
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = false;
2432
};
2533

2634
_LIBCPP_END_NAMESPACE_STD

libcxx/include/deque

+2-3
Original file line numberDiff line numberDiff line change
@@ -2618,9 +2618,8 @@ struct __container_traits<deque<_Tp, _Allocator> > {
26182618
// assignment operator of T, there are no effects. If an exception is thrown while inserting a single element at
26192619
// either end, there are no effects. Otherwise, if an exception is thrown by the move constructor of a
26202620
// non-Cpp17CopyInsertable T, the effects are unspecified.
2621-
using __emplacement_has_strong_exception_safety_guarantee =
2622-
_Or<is_nothrow_move_constructible<_Tp>,
2623-
__is_cpp17_copy_insertable<typename deque<_Tp, _Allocator>::allocator_type> >;
2621+
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
2622+
_Or<is_nothrow_move_constructible<_Tp>, __is_cpp17_copy_insertable<_Allocator> >::value;
26242623
};
26252624

26262625
_LIBCPP_END_NAMESPACE_STD

libcxx/include/forward_list

+3-3
Original file line numberDiff line numberDiff line change
@@ -1548,12 +1548,12 @@ erase(forward_list<_Tp, _Allocator>& __c, const _Up& __v) {
15481548
template <class _Tp, class _Allocator>
15491549
struct __container_traits<forward_list<_Tp, _Allocator> > {
15501550
// http://eel.is/c++draft/container.reqmts
1551-
// 66 Unless otherwise specified (see [associative.reqmts.except], [unord.req.except], [deque.modifiers],
1551+
// Unless otherwise specified (see [associative.reqmts.except], [unord.req.except], [deque.modifiers],
15521552
// [inplace.vector.modifiers], and [vector.modifiers]) all container types defined in this Clause meet the following
15531553
// additional requirements:
1554-
// - (66.1) If an exception is thrown by an insert() or emplace() function while inserting a single element, that
1554+
// - If an exception is thrown by an insert() or emplace() function while inserting a single element, that
15551555
// function has no effects.
1556-
using __emplacement_has_strong_exception_safety_guarantee = true_type;
1556+
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
15571557
};
15581558

15591559
_LIBCPP_END_NAMESPACE_STD

libcxx/include/list

+3-3
Original file line numberDiff line numberDiff line change
@@ -1719,12 +1719,12 @@ inline constexpr bool __format::__enable_insertable<std::list<wchar_t>> = true;
17191719
template <class _Tp, class _Allocator>
17201720
struct __container_traits<list<_Tp, _Allocator> > {
17211721
// http://eel.is/c++draft/container.reqmts
1722-
// 66 Unless otherwise specified (see [associative.reqmts.except], [unord.req.except], [deque.modifiers],
1722+
// Unless otherwise specified (see [associative.reqmts.except], [unord.req.except], [deque.modifiers],
17231723
// [inplace.vector.modifiers], and [vector.modifiers]) all container types defined in this Clause meet the following
17241724
// additional requirements:
1725-
// - (66.1) If an exception is thrown by an insert() or emplace() function while inserting a single element, that
1725+
// - If an exception is thrown by an insert() or emplace() function while inserting a single element, that
17261726
// function has no effects.
1727-
using __emplacement_has_strong_exception_safety_guarantee = true_type;
1727+
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
17281728
};
17291729

17301730
_LIBCPP_END_NAMESPACE_STD

libcxx/include/map

+2-2
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ struct __container_traits<map<_Key, _Tp, _Compare, _Allocator> > {
16501650
// http://eel.is/c++draft/associative.reqmts.except#2
16511651
// For associative containers, if an exception is thrown by any operation from within
16521652
// an insert or emplace function inserting a single element, the insertion has no effect.
1653-
using __emplacement_has_strong_exception_safety_guarantee = true_type;
1653+
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
16541654
};
16551655

16561656
template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
@@ -2172,7 +2172,7 @@ struct __container_traits<multimap<_Key, _Tp, _Compare, _Allocator> > {
21722172
// http://eel.is/c++draft/associative.reqmts.except#2
21732173
// For associative containers, if an exception is thrown by any operation from within
21742174
// an insert or emplace function inserting a single element, the insertion has no effect.
2175-
using __emplacement_has_strong_exception_safety_guarantee = true_type;
2175+
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
21762176
};
21772177

21782178
_LIBCPP_END_NAMESPACE_STD

libcxx/include/set

+2-2
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ struct __container_traits<set<_Key, _Compare, _Allocator> > {
10281028
// http://eel.is/c++draft/associative.reqmts.except#2
10291029
// For associative containers, if an exception is thrown by any operation from within
10301030
// an insert or emplace function inserting a single element, the insertion has no effect.
1031-
using __emplacement_has_strong_exception_safety_guarantee = true_type;
1031+
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
10321032
};
10331033

10341034
template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
@@ -1495,7 +1495,7 @@ struct __container_traits<multiset<_Key, _Compare, _Allocator> > {
14951495
// http://eel.is/c++draft/associative.reqmts.except#2
14961496
// For associative containers, if an exception is thrown by any operation from within
14971497
// an insert or emplace function inserting a single element, the insertion has no effect.
1498-
using __emplacement_has_strong_exception_safety_guarantee = true_type;
1498+
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
14991499
};
15001500

15011501
_LIBCPP_END_NAMESPACE_STD

libcxx/include/unordered_map

+5-2
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
606606
#include <__ranges/from_range.h>
607607
#include <__type_traits/container_traits.h>
608608
#include <__type_traits/enable_if.h>
609+
#include <__type_traits/invoke.h>
609610
#include <__type_traits/is_allocator.h>
610611
#include <__type_traits/is_integral.h>
611612
#include <__type_traits/remove_const.h>
@@ -1837,7 +1838,8 @@ struct __container_traits<unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc> > {
18371838
// For unordered associative containers, if an exception is thrown by any operation
18381839
// other than the container's hash function from within an insert or emplace function
18391840
// inserting a single element, the insertion has no effect.
1840-
using __emplacement_has_strong_exception_safety_guarantee = __nothrow_invokable<_Hash, const _Key&>;
1841+
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
1842+
__nothrow_invokable<_Hash, const _Key&>::value;
18411843
};
18421844

18431845
template <class _Key,
@@ -2536,7 +2538,8 @@ struct __container_traits<unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc> >
25362538
// For unordered associative containers, if an exception is thrown by any operation
25372539
// other than the container's hash function from within an insert or emplace function
25382540
// inserting a single element, the insertion has no effect.
2539-
using __emplacement_has_strong_exception_safety_guarantee = __nothrow_invokable<_Hash, const _Key&>;
2541+
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
2542+
__nothrow_invokable<_Hash, const _Key&>::value;
25402543
};
25412544

25422545
_LIBCPP_END_NAMESPACE_STD

libcxx/include/unordered_set

+5-2
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ template <class Value, class Hash, class Pred, class Alloc>
552552
#include <__ranges/from_range.h>
553553
#include <__type_traits/container_traits.h>
554554
#include <__type_traits/enable_if.h>
555+
#include <__type_traits/invoke.h>
555556
#include <__type_traits/is_allocator.h>
556557
#include <__type_traits/is_integral.h>
557558
#include <__type_traits/is_nothrow_assignable.h>
@@ -1190,7 +1191,8 @@ struct __container_traits<unordered_set<_Value, _Hash, _Pred, _Alloc> > {
11901191
// For unordered associative containers, if an exception is thrown by any operation
11911192
// other than the container's hash function from within an insert or emplace function
11921193
// inserting a single element, the insertion has no effect.
1193-
using __emplacement_has_strong_exception_safety_guarantee = __nothrow_invokable<_Hash, const _Value&>;
1194+
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
1195+
__nothrow_invokable<_Hash, const _Value&>::value;
11941196
};
11951197

11961198
template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, class _Alloc = allocator<_Value> >
@@ -1809,7 +1811,8 @@ struct __container_traits<unordered_multiset<_Value, _Hash, _Pred, _Alloc> > {
18091811
// For unordered associative containers, if an exception is thrown by any operation
18101812
// other than the container's hash function from within an insert or emplace function
18111813
// inserting a single element, the insertion has no effect.
1812-
using __emplacement_has_strong_exception_safety_guarantee = __nothrow_invokable<_Hash, const _Value&>;
1814+
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
1815+
__nothrow_invokable<_Hash, const _Value&>::value;
18131816
};
18141817

18151818
_LIBCPP_END_NAMESPACE_STD

libcxx/include/vector

+2-3
Original file line numberDiff line numberDiff line change
@@ -3015,9 +3015,8 @@ struct __container_traits<vector<_Tp, _Allocator> > {
30153015
// inserting a single element at the end and T is Cpp17CopyInsertable or is_nothrow_move_constructible_v<T> is true,
30163016
// there are no effects. Otherwise, if an exception is thrown by the move constructor of a non-Cpp17CopyInsertable T,
30173017
// the effects are unspecified.
3018-
using __emplacement_has_strong_exception_safety_guarantee =
3019-
_Or<is_nothrow_move_constructible<_Tp>,
3020-
__is_cpp17_copy_insertable<typename vector<_Tp, _Allocator>::allocator_type> >;
3018+
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
3019+
_Or<is_nothrow_move_constructible<_Tp>, __is_cpp17_copy_insertable<_Allocator> >::value;
30213020
};
30223021

30233022
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)