[libcxx-commits] [libcxx] [libcxx] changes `__is_allocator` from a struct to a variable or concept (PR #68629)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Oct 9 13:53:20 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
<details>
<summary>Changes</summary>
Having `__is_allocator` be a concept when concepts are available is advantageous for diagnostic quality. Since libc++ doesn't use `__is_allocator` as a struct, we can turn it into an inline bool whenever concepts aren't available and retain the same syntax.
This change requires disabling warnings for C++14 and C++17 extensions (template variables and inline variables, respectively), but these ones are both supported in GCC anyway (see https://godbolt.org/z/M5frbxefP).
---
Patch is 63.54 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/68629.diff
15 Files Affected:
- (modified) libcxx/include/__type_traits/is_allocator.h (+11-3)
- (modified) libcxx/include/deque (+4-4)
- (modified) libcxx/include/forward_list (+4-4)
- (modified) libcxx/include/list (+4-4)
- (modified) libcxx/include/map (+18-18)
- (modified) libcxx/include/queue (+19-19)
- (modified) libcxx/include/set (+18-18)
- (modified) libcxx/include/sstream (+4-4)
- (modified) libcxx/include/stack (+4-4)
- (modified) libcxx/include/string (+7-7)
- (modified) libcxx/include/unordered_map (+42-42)
- (modified) libcxx/include/unordered_set (+38-38)
- (modified) libcxx/include/vector (+4-4)
- (modified) libcxx/test/libcxx/memory/is_allocator.pass.cpp (+4-4)
- (modified) libcxx/utils/libcxx/test/params.py (+2)
``````````diff
diff --git a/libcxx/include/__type_traits/is_allocator.h b/libcxx/include/__type_traits/is_allocator.h
index 144ffac4d7ce5b0..b926bb6a6f36075 100644
--- a/libcxx/include/__type_traits/is_allocator.h
+++ b/libcxx/include/__type_traits/is_allocator.h
@@ -21,13 +21,21 @@
_LIBCPP_BEGIN_NAMESPACE_STD
+#if _LIBCPP_STD_VER >= 20
+template<class _Alloc>
+concept __is_allocator = requires(_Alloc __a) {
+ typename _Alloc::value_type;
+ __a.allocate(size_t(0));
+};
+#else
template <typename _Alloc, typename = void, typename = void>
-struct __is_allocator : false_type {};
+inline static const bool __is_allocator = false;
template <typename _Alloc>
-struct __is_allocator<_Alloc,
+inline static const bool __is_allocator<_Alloc,
__void_t<typename _Alloc::value_type>,
- __void_t<decltype(std::declval<_Alloc&>().allocate(size_t(0)))> > : true_type {};
+ __void_t<decltype(std::declval<_Alloc&>().allocate(size_t(0)))> > = true;
+#endif
_LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/include/deque b/libcxx/include/deque
index 6b6d8e2bdda6682..8a536dfb56e1218 100644
--- a/libcxx/include/deque
+++ b/libcxx/include/deque
@@ -604,7 +604,7 @@ public:
#endif
_LIBCPP_HIDE_FROM_ABI deque(size_type __n, const value_type& __v);
- template <class = __enable_if_t<__is_allocator<_Allocator>::value> >
+ template <class = __enable_if_t<__is_allocator<_Allocator> > >
_LIBCPP_HIDE_FROM_ABI deque(size_type __n, const value_type& __v, const allocator_type& __a)
: __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a)
{
@@ -1314,7 +1314,7 @@ _LIBCPP_CONSTEXPR const typename allocator_traits<_Alloc>::difference_type deque
template<class _InputIterator,
class _Alloc = allocator<__iter_value_type<_InputIterator>>,
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
- class = enable_if_t<__is_allocator<_Alloc>::value>
+ class = enable_if_t<__is_allocator<_Alloc> >
>
deque(_InputIterator, _InputIterator)
-> deque<__iter_value_type<_InputIterator>, _Alloc>;
@@ -1322,7 +1322,7 @@ deque(_InputIterator, _InputIterator)
template<class _InputIterator,
class _Alloc,
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
- class = enable_if_t<__is_allocator<_Alloc>::value>
+ class = enable_if_t<__is_allocator<_Alloc> >
>
deque(_InputIterator, _InputIterator, _Alloc)
-> deque<__iter_value_type<_InputIterator>, _Alloc>;
@@ -1331,7 +1331,7 @@ deque(_InputIterator, _InputIterator, _Alloc)
#if _LIBCPP_STD_VER >= 23
template <ranges::input_range _Range,
class _Alloc = allocator<ranges::range_value_t<_Range>>,
- class = enable_if_t<__is_allocator<_Alloc>::value>
+ class = enable_if_t<__is_allocator<_Alloc> >
>
deque(from_range_t, _Range&&, _Alloc = _Alloc())
-> deque<ranges::range_value_t<_Range>, _Alloc>;
diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list
index 75ac685cc02839e..523717290acfff8 100644
--- a/libcxx/include/forward_list
+++ b/libcxx/include/forward_list
@@ -736,7 +736,7 @@ public:
#endif
_LIBCPP_HIDE_FROM_ABI forward_list(size_type __n, const value_type& __v);
- template <class = __enable_if_t<__is_allocator<_Alloc>::value> >
+ template <class = __enable_if_t<__is_allocator<_Alloc> > >
_LIBCPP_HIDE_FROM_ABI forward_list(size_type __n, const value_type& __v, const allocator_type& __a) : base(__a)
{
insert_after(cbefore_begin(), __n, __v);
@@ -982,7 +982,7 @@ private:
template<class _InputIterator,
class _Alloc = allocator<__iter_value_type<_InputIterator>>,
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
- class = enable_if_t<__is_allocator<_Alloc>::value>
+ class = enable_if_t<__is_allocator<_Alloc> >
>
forward_list(_InputIterator, _InputIterator)
-> forward_list<__iter_value_type<_InputIterator>, _Alloc>;
@@ -990,7 +990,7 @@ forward_list(_InputIterator, _InputIterator)
template<class _InputIterator,
class _Alloc,
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
- class = enable_if_t<__is_allocator<_Alloc>::value>
+ class = enable_if_t<__is_allocator<_Alloc> >
>
forward_list(_InputIterator, _InputIterator, _Alloc)
-> forward_list<__iter_value_type<_InputIterator>, _Alloc>;
@@ -999,7 +999,7 @@ forward_list(_InputIterator, _InputIterator, _Alloc)
#if _LIBCPP_STD_VER >= 23
template <ranges::input_range _Range,
class _Alloc = allocator<ranges::range_value_t<_Range>>,
- class = enable_if_t<__is_allocator<_Alloc>::value>
+ class = enable_if_t<__is_allocator<_Alloc> >
>
forward_list(from_range_t, _Range&&, _Alloc = _Alloc())
-> forward_list<ranges::range_value_t<_Range>, _Alloc>;
diff --git a/libcxx/include/list b/libcxx/include/list
index b02599bc3fe7c3e..00f7bf6f274cacb 100644
--- a/libcxx/include/list
+++ b/libcxx/include/list
@@ -779,7 +779,7 @@ public:
_LIBCPP_HIDE_FROM_ABI explicit list(size_type __n, const allocator_type& __a);
#endif
_LIBCPP_HIDE_FROM_ABI list(size_type __n, const value_type& __x);
- template <class = __enable_if_t<__is_allocator<_Alloc>::value> >
+ template <class = __enable_if_t<__is_allocator<_Alloc> > >
_LIBCPP_HIDE_FROM_ABI list(size_type __n, const value_type& __x, const allocator_type& __a) : base(__a)
{
for (; __n > 0; --__n)
@@ -1075,7 +1075,7 @@ private:
template<class _InputIterator,
class _Alloc = allocator<__iter_value_type<_InputIterator>>,
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
- class = enable_if_t<__is_allocator<_Alloc>::value>
+ class = enable_if_t<__is_allocator<_Alloc> >
>
list(_InputIterator, _InputIterator)
-> list<__iter_value_type<_InputIterator>, _Alloc>;
@@ -1083,7 +1083,7 @@ list(_InputIterator, _InputIterator)
template<class _InputIterator,
class _Alloc,
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
- class = enable_if_t<__is_allocator<_Alloc>::value>
+ class = enable_if_t<__is_allocator<_Alloc> >
>
list(_InputIterator, _InputIterator, _Alloc)
-> list<__iter_value_type<_InputIterator>, _Alloc>;
@@ -1092,7 +1092,7 @@ list(_InputIterator, _InputIterator, _Alloc)
#if _LIBCPP_STD_VER >= 23
template <ranges::input_range _Range,
class _Alloc = allocator<ranges::range_value_t<_Range>>,
- class = enable_if_t<__is_allocator<_Alloc>::value>
+ class = enable_if_t<__is_allocator<_Alloc> >
>
list(from_range_t, _Range&&, _Alloc = _Alloc())
-> list<ranges::range_value_t<_Range>, _Alloc>;
diff --git a/libcxx/include/map b/libcxx/include/map
index 17bb715f249d756..abfa7749ece146b 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -1630,43 +1630,43 @@ private:
template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
- class = enable_if_t<!__is_allocator<_Compare>::value, void>,
- class = enable_if_t<__is_allocator<_Allocator>::value, void>>
+ class = enable_if_t<!__is_allocator<_Compare> , void>,
+ class = enable_if_t<__is_allocator<_Allocator> , void>>
map(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
-> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
#if _LIBCPP_STD_VER >= 23
template <ranges::input_range _Range, class _Compare = less<__range_key_type<_Range>>,
class _Allocator = allocator<__range_to_alloc_type<_Range>>,
- class = enable_if_t<!__is_allocator<_Compare>::value, void>,
- class = enable_if_t<__is_allocator<_Allocator>::value, void>>
+ class = enable_if_t<!__is_allocator<_Compare> , void>,
+ class = enable_if_t<__is_allocator<_Allocator> , void>>
map(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator())
-> map<__range_key_type<_Range>, __range_mapped_type<_Range>, _Compare, _Allocator>;
#endif
template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
class _Allocator = allocator<pair<const _Key, _Tp>>,
- class = enable_if_t<!__is_allocator<_Compare>::value, void>,
- class = enable_if_t<__is_allocator<_Allocator>::value, void>>
+ class = enable_if_t<!__is_allocator<_Compare> , void>,
+ class = enable_if_t<__is_allocator<_Allocator> , void>>
map(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
-> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
template<class _InputIterator, class _Allocator,
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
- class = enable_if_t<__is_allocator<_Allocator>::value, void>>
+ class = enable_if_t<__is_allocator<_Allocator> , void>>
map(_InputIterator, _InputIterator, _Allocator)
-> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
less<__iter_key_type<_InputIterator>>, _Allocator>;
#if _LIBCPP_STD_VER >= 23
template <ranges::input_range _Range, class _Allocator,
- class = enable_if_t<__is_allocator<_Allocator>::value, void>>
+ class = enable_if_t<__is_allocator<_Allocator> , void>>
map(from_range_t, _Range&&, _Allocator)
-> map<__range_key_type<_Range>, __range_mapped_type<_Range>, less<__range_key_type<_Range>>, _Allocator>;
#endif
template<class _Key, class _Tp, class _Allocator,
- class = enable_if_t<__is_allocator<_Allocator>::value, void>>
+ class = enable_if_t<__is_allocator<_Allocator> , void>>
map(initializer_list<pair<_Key, _Tp>>, _Allocator)
-> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
#endif
@@ -2360,43 +2360,43 @@ private:
template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
- class = enable_if_t<!__is_allocator<_Compare>::value, void>,
- class = enable_if_t<__is_allocator<_Allocator>::value, void>>
+ class = enable_if_t<!__is_allocator<_Compare> , void>,
+ class = enable_if_t<__is_allocator<_Allocator> , void>>
multimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
-> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
#if _LIBCPP_STD_VER >= 23
template <ranges::input_range _Range, class _Compare = less<__range_key_type<_Range>>,
class _Allocator = allocator<__range_to_alloc_type<_Range>>,
- class = enable_if_t<!__is_allocator<_Compare>::value, void>,
- class = enable_if_t<__is_allocator<_Allocator>::value, void>>
+ class = enable_if_t<!__is_allocator<_Compare> , void>,
+ class = enable_if_t<__is_allocator<_Allocator> , void>>
multimap(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator())
-> multimap<__range_key_type<_Range>, __range_mapped_type<_Range>, _Compare, _Allocator>;
#endif
template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
class _Allocator = allocator<pair<const _Key, _Tp>>,
- class = enable_if_t<!__is_allocator<_Compare>::value, void>,
- class = enable_if_t<__is_allocator<_Allocator>::value, void>>
+ class = enable_if_t<!__is_allocator<_Compare> , void>,
+ class = enable_if_t<__is_allocator<_Allocator> , void>>
multimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
-> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
template<class _InputIterator, class _Allocator,
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
- class = enable_if_t<__is_allocator<_Allocator>::value, void>>
+ class = enable_if_t<__is_allocator<_Allocator> , void>>
multimap(_InputIterator, _InputIterator, _Allocator)
-> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
less<__iter_key_type<_InputIterator>>, _Allocator>;
#if _LIBCPP_STD_VER >= 23
template <ranges::input_range _Range, class _Allocator,
- class = enable_if_t<__is_allocator<_Allocator>::value, void>>
+ class = enable_if_t<__is_allocator<_Allocator> , void>>
multimap(from_range_t, _Range&&, _Allocator)
-> multimap<__range_key_type<_Range>, __range_mapped_type<_Range>, less<__range_key_type<_Range>>, _Allocator>;
#endif
template<class _Key, class _Tp, class _Allocator,
- class = enable_if_t<__is_allocator<_Allocator>::value, void>>
+ class = enable_if_t<__is_allocator<_Allocator> , void>>
multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
-> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
#endif
diff --git a/libcxx/include/queue b/libcxx/include/queue
index 21c18ef43154714..950a7db4f12baba 100644
--- a/libcxx/include/queue
+++ b/libcxx/include/queue
@@ -468,14 +468,14 @@ public:
#if _LIBCPP_STD_VER >= 17
template<class _Container,
- class = enable_if_t<!__is_allocator<_Container>::value>
+ class = enable_if_t<!__is_allocator<_Container> >
>
queue(_Container)
-> queue<typename _Container::value_type, _Container>;
template<class _Container,
class _Alloc,
- class = enable_if_t<!__is_allocator<_Container>::value>,
+ class = enable_if_t<!__is_allocator<_Container> >,
class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
>
queue(_Container, _Alloc)
@@ -495,13 +495,13 @@ queue(from_range_t, _Range&&)
template <class _InputIterator,
class _Alloc,
class = __enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
- class = __enable_if_t<__is_allocator<_Alloc>::value>>
+ class = __enable_if_t<__is_allocator<_Alloc> >>
queue(_InputIterator, _InputIterator, _Alloc)
-> queue<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>;
template <ranges::input_range _Range,
class _Alloc,
- class = __enable_if_t<__is_allocator<_Alloc>::value>>
+ class = __enable_if_t<__is_allocator<_Alloc> >>
queue(from_range_t, _Range&&, _Alloc)
-> queue<ranges::range_value_t<_Range>, deque<ranges::range_value_t<_Range>, _Alloc>>;
#endif
@@ -784,8 +784,8 @@ public:
#if _LIBCPP_STD_VER >= 17
template <class _Compare,
class _Container,
- class = enable_if_t<!__is_allocator<_Compare>::value>,
- class = enable_if_t<!__is_allocator<_Container>::value>
+ class = enable_if_t<!__is_allocator<_Compare> >,
+ class = enable_if_t<!__is_allocator<_Container> >
>
priority_queue(_Compare, _Container)
-> priority_queue<typename _Container::value_type, _Container, _Compare>;
@@ -794,8 +794,8 @@ template<class _InputIterator,
class _Compare = less<__iter_value_type<_InputIterator>>,
class _Container = vector<__iter_value_type<_InputIterator>>,
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
- class = enable_if_t<!__is_allocator<_Compare>::value>,
- class = enable_if_t<!__is_allocator<_Container>::value>
+ class = enable_if_t<!__is_allocator<_Compare> >,
+ class = enable_if_t<!__is_allocator<_Container> >
>
priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container())
-> priority_queue<__iter_value_type<_InputIterator>, _Container, _Compare>;
@@ -803,8 +803,8 @@ priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container
template<class _Compare,
class _Container,
class _Alloc,
- class = enable_if_t<!__is_allocator<_Compare>::value>,
- class = enable_if_t<!__is_allocator<_Container>::value>,
+ class = enable_if_t<!__is_allocator<_Compare> >,
+ class = enable_if_t<!__is_allocator<_Container> >,
class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
>
priority_queue(_Compare, _Container, _Alloc)
@@ -812,7 +812,7 @@ priority_queue(_Compare, _Container, _Alloc)
template<class _InputIterator, class _Allocator,
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
- class = enable_if_t<__is_allocator<_Allocator>::value>
+ class = enable_if_t<__is_allocator<_Allocator> >
>
priority_queue(_InputIterator, _InputIterator, _Allocator)
-> priority_queue<__iter_value_type<_InputIterator>,
@@ -821,8 +821,8 @@ priority_queue(_InputIterator, _InputIterator, _Allocator)
template<class _InputIterator, class _Compare, class _Allocator,
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
- class = enable_if_t<!__is_allocator<_Compare>::value>,
- class = enable_if_t<__is_allocator<_Allocator>::value>
+ class = enable_if_t<!__is_allocator<_Compare> >,
+ class = enable_if_t<__is_allocator<_Allocator> >
>
priority_queue(_InputIterator, _InputIterator, _Compare, _Allocator)
-> priority_queue<__iter_value_type<_InputIterator>,
@@ -830,8 +830,8 @@ priority_queue(_InputIterator, _InputIterator, _Compare, _Allocator)
template<class _InputIterator, class _Compare, class _Container, class _Alloc,
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
- class = enable_if_t<!__is_allocator<_Compare>::value>,
- class = enable_if_t<!__is_allocator<_Container>::value>,
+ class = enable_if_t<!__is_allocator<_Compare> >,
+ class = enable_if_t<!__is_allocator<_Container> >,
class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
>
priority_queue(_InputIterator, _InputIterator, _Compare, _Container, _Alloc)
@@ -842,22 +842,22 @@ priority_queue(_InputIterator, _InputIterator, _Compare, _Container, _Alloc)
template <ranges::input_range _Range,
class _Compare = less<ranges::range_value_t<_Range>>,
- class = enable_if_t<!__is_allocator<_Compare>::value>>
+ class = enable_if_t<!__is_allocator<_Compare> >>
priority_queue(from_range_t, _Range&&, _Compare = _Compare())
-> priority_queue<ranges::range_value_t<_Range>, vector<ranges::range_value_t<_Range>>, _Compare>;
template <ranges::input_range _Range,
class _Compare,
class _Alloc,
- class = enable_if_t<!__is_allocator<_Compare>::value>,
- class = enable_if_t<__is_allocator<_Alloc>::value>>
+ class = enable_if_t<!__is_allocator<_Compare> >,
+ class = enable_if_t<__is_allocator<_Alloc> >>
priority_queue(from_range_t, _Range&&, _Compare, _Alloc)
-> priority_queue<ranges::range_value_t<_Range>, vector<ranges::range_value_t<_Range>, _Alloc>,
_Compare>;
template <ranges::input_range _Range,
class _Alloc,
- class = enable_if_t<__is_allocator<_Alloc>::value>>
+ class = enable_if_t<__is_allocator<_Alloc> >>
priority_queue(from_range_t, _Range&&, _Alloc)
-> priority_queue<ranges::range_value_t<_Range>, vector<ranges::range_value_t<_Range>, _Alloc>>;
diff --git a/libcxx/include/set b/libcxx/include/set
index 75be1e13ede511d..a87a29c93751b8b 100644
--- a/libcxx/include/set
+++ b/libcxx/include/set
@@ -1007,43 +1007,43 @@ template<class _InputIterator,
class _Compare = less<__iter_value_type<_InputIterator>>,
class _Allocator = allocator<__iter_value_type<_InputIterator>>,
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
- class = enable_if_t<__is_allocator<_Allocator>::value, void>,
- class = enable_if_t<!__is_allocator<_Compare>::value, void>>
+ class = enable_if_t<__is_allocator<_Allocator> , void>,
+ class = enable_if_t<!__is_allocator<_Compare> ...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/68629
More information about the libcxx-commits
mailing list