[libcxx-commits] [libcxx] [libc++] Use template variables in a bunch of places instead of class templates (PR #139518)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon May 12 02:15:38 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions ,cpp,h -- libcxx/include/__algorithm/equal.h libcxx/include/__algorithm/equal_range.h libcxx/include/__algorithm/find.h libcxx/include/__algorithm/includes.h libcxx/include/__algorithm/is_permutation.h libcxx/include/__algorithm/lexicographical_compare.h libcxx/include/__algorithm/lower_bound.h libcxx/include/__algorithm/max_element.h libcxx/include/__algorithm/min_element.h libcxx/include/__algorithm/minmax.h libcxx/include/__algorithm/minmax_element.h libcxx/include/__algorithm/mismatch.h libcxx/include/__algorithm/partial_sort_copy.h libcxx/include/__algorithm/search.h libcxx/include/__algorithm/search_n.h libcxx/include/__algorithm/upper_bound.h libcxx/include/__expected/expected.h libcxx/include/__expected/unexpected.h libcxx/include/__flat_map/flat_map.h libcxx/include/__flat_map/flat_multimap.h libcxx/include/__flat_set/flat_multiset.h libcxx/include/__flat_set/flat_set.h libcxx/include/__functional/bind.h libcxx/include/__functional/function.h libcxx/include/__hash_table libcxx/include/__mdspan/extents.h libcxx/include/__mdspan/layout_left.h libcxx/include/__mdspan/layout_right.h libcxx/include/__mdspan/layout_stride.h libcxx/include/__memory/shared_ptr.h libcxx/include/__random/discard_block_engine.h libcxx/include/__random/independent_bits_engine.h libcxx/include/__random/is_seed_sequence.h libcxx/include/__random/linear_congruential_engine.h libcxx/include/__random/mersenne_twister_engine.h libcxx/include/__random/shuffle_order_engine.h libcxx/include/__random/subtract_with_carry_engine.h libcxx/include/__string/constexpr_c_functions.h libcxx/include/__type_traits/invoke.h libcxx/include/__type_traits/is_allocator.h libcxx/include/__type_traits/is_callable.h libcxx/include/__type_traits/is_core_convertible.h libcxx/include/__type_traits/is_equality_comparable.h libcxx/include/__type_traits/is_reference_wrapper.h libcxx/include/__utility/in_place.h libcxx/include/__utility/is_pointer_in_range.h libcxx/include/__vector/vector.h libcxx/include/any libcxx/include/cwchar libcxx/include/deque libcxx/include/experimental/propagate_const libcxx/include/forward_list libcxx/include/list libcxx/include/map libcxx/include/optional libcxx/include/queue libcxx/include/set libcxx/include/span libcxx/include/sstream libcxx/include/stack libcxx/include/string libcxx/include/unordered_map libcxx/include/unordered_set libcxx/include/valarray libcxx/include/variant libcxx/test/libcxx/memory/is_allocator.pass.cpp libcxx/test/libcxx/type_traits/is_callable.compile.pass.cpp libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp libcxx/test/libcxx/utilities/utility/__is_inplace_index.pass.cpp libcxx/test/libcxx/utilities/utility/__is_inplace_type.pass.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libcxx/include/__flat_map/flat_multimap.h b/libcxx/include/__flat_map/flat_multimap.h
index 4710fab50..58072f66b 100644
--- a/libcxx/include/__flat_map/flat_multimap.h
+++ b/libcxx/include/__flat_map/flat_multimap.h
@@ -898,8 +898,7 @@ flat_multimap(_KeyContainer, _MappedContainer, _Compare, _Allocator)
_MappedContainer>;
template <class _KeyContainer, class _MappedContainer, class _Compare = less<typename _KeyContainer::value_type>>
- requires(!__is_allocator_v<_Compare> && !__is_allocator_v<_KeyContainer> &&
- !__is_allocator_v<_MappedContainer> &&
+ requires(!__is_allocator_v<_Compare> && !__is_allocator_v<_KeyContainer> && !__is_allocator_v<_MappedContainer> &&
is_invocable_v<const _Compare&,
const typename _KeyContainer::value_type&,
const typename _KeyContainer::value_type&>)
@@ -921,9 +920,8 @@ flat_multimap(sorted_equivalent_t, _KeyContainer, _MappedContainer, _Allocator)
_MappedContainer>;
template <class _KeyContainer, class _MappedContainer, class _Compare, class _Allocator>
- requires(!__is_allocator_v<_Compare> && !__is_allocator_v<_KeyContainer> &&
- !__is_allocator_v<_MappedContainer> && uses_allocator_v<_KeyContainer, _Allocator> &&
- uses_allocator_v<_MappedContainer, _Allocator> &&
+ requires(!__is_allocator_v<_Compare> && !__is_allocator_v<_KeyContainer> && !__is_allocator_v<_MappedContainer> &&
+ uses_allocator_v<_KeyContainer, _Allocator> && uses_allocator_v<_MappedContainer, _Allocator> &&
is_invocable_v<const _Compare&,
const typename _KeyContainer::value_type&,
const typename _KeyContainer::value_type&>)
diff --git a/libcxx/include/any b/libcxx/include/any
index 04b9acd97..76575d803 100644
--- a/libcxx/include/any
+++ b/libcxx/include/any
@@ -207,7 +207,7 @@ public:
template <
class _ValueType,
class _Tp = decay_t<_ValueType>,
- class = enable_if_t<!is_same_v<_Tp, any> && !__is_in_place_type_v<_ValueType> && is_copy_constructible_v<_Tp>>>
+ class = enable_if_t<!is_same_v<_Tp, any> && !__is_in_place_type_v<_ValueType> && is_copy_constructible_v<_Tp>>>
_LIBCPP_HIDE_FROM_ABI any(_ValueType&& __value);
template <class _ValueType,
diff --git a/libcxx/include/cwchar b/libcxx/include/cwchar
index d41af176f..03db9e5fb 100644
--- a/libcxx/include/cwchar
+++ b/libcxx/include/cwchar
@@ -231,7 +231,7 @@ __constexpr_wmemcmp(const wchar_t* __lhs, const wchar_t* __rhs, size_t __count)
template <class _Tp, class _Up>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __constexpr_wmemchr(_Tp* __str, _Up __value, size_t __count) {
- static_assert(sizeof(_Tp) == sizeof(wchar_t) && _LIBCPP_ALIGNOF(_Tp) >= _LIBCPP_ALIGNOF(wchar_t) &&
+ static_assert(sizeof(_Tp) == sizeof(wchar_t)&& _LIBCPP_ALIGNOF(_Tp) >= _LIBCPP_ALIGNOF(wchar_t) &&
__is_trivially_equality_comparable_v<_Tp, _Tp>,
"Calling wmemchr on non-trivially equality comparable types is unsafe.");
diff --git a/libcxx/include/map b/libcxx/include/map
index abd64278b..f88804d5a 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -1479,9 +1479,8 @@ template <class _Key,
class _Allocator = allocator<pair<const _Key, _Tp>>,
class = enable_if_t<!__is_allocator_v<_Compare>>,
class = enable_if_t<__is_allocator_v<_Allocator>>>
-map(initializer_list<pair<_Key, _Tp>>,
- _Compare = _Compare(),
- _Allocator = _Allocator()) -> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
+map(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
+ -> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
template <class _InputIterator,
class _Allocator,
@@ -1500,8 +1499,8 @@ map(from_range_t, _Range&&, _Allocator)
# endif
template <class _Key, class _Tp, class _Allocator, class = enable_if_t<__is_allocator_v<_Allocator>>>
-map(initializer_list<pair<_Key, _Tp>>,
- _Allocator) -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
+map(initializer_list<pair<_Key, _Tp>>, _Allocator)
+ -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
# endif
# ifndef _LIBCPP_CXX03_LANG
@@ -2068,9 +2067,8 @@ template <class _Key,
class _Allocator = allocator<pair<const _Key, _Tp>>,
class = enable_if_t<!__is_allocator_v<_Compare>>,
class = enable_if_t<__is_allocator_v<_Allocator>>>
-multimap(initializer_list<pair<_Key, _Tp>>,
- _Compare = _Compare(),
- _Allocator = _Allocator()) -> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
+multimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
+ -> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
template <class _InputIterator,
class _Allocator,
@@ -2089,8 +2087,8 @@ multimap(from_range_t, _Range&&, _Allocator)
# endif
template <class _Key, class _Tp, class _Allocator, class = enable_if_t<__is_allocator_v<_Allocator>>>
-multimap(initializer_list<pair<_Key, _Tp>>,
- _Allocator) -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
+multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
+ -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
# endif
# ifndef _LIBCPP_CXX03_LANG
diff --git a/libcxx/include/queue b/libcxx/include/queue
index 936cdbc50..709940234 100644
--- a/libcxx/include/queue
+++ b/libcxx/include/queue
@@ -458,14 +458,12 @@ template <class _InputIterator,
class _Alloc,
__enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0,
__enable_if_t<__is_allocator_v<_Alloc>, int> = 0>
-queue(_InputIterator,
- _InputIterator,
- _Alloc) -> queue<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>;
+queue(_InputIterator, _InputIterator, _Alloc)
+ -> queue<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>;
template <ranges::input_range _Range, class _Alloc, __enable_if_t<__is_allocator_v<_Alloc>, int> = 0>
-queue(from_range_t,
- _Range&&,
- _Alloc) -> queue<ranges::range_value_t<_Range>, deque<ranges::range_value_t<_Range>, _Alloc>>;
+queue(from_range_t, _Range&&, _Alloc)
+ -> queue<ranges::range_value_t<_Range>, deque<ranges::range_value_t<_Range>, _Alloc>>;
# endif
template <class _Tp, class _Container>
diff --git a/libcxx/include/set b/libcxx/include/set
index 45e40d314..86550470e 100644
--- a/libcxx/include/set
+++ b/libcxx/include/set
@@ -933,15 +933,13 @@ template <class _InputIterator,
class _Allocator,
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
class = enable_if_t<__is_allocator_v<_Allocator>>>
-set(_InputIterator,
- _InputIterator,
- _Allocator) -> set<__iter_value_type<_InputIterator>, less<__iter_value_type<_InputIterator>>, _Allocator>;
+set(_InputIterator, _InputIterator, _Allocator)
+ -> set<__iter_value_type<_InputIterator>, less<__iter_value_type<_InputIterator>>, _Allocator>;
# if _LIBCPP_STD_VER >= 23
template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator_v<_Allocator>>>
-set(from_range_t,
- _Range&&,
- _Allocator) -> set<ranges::range_value_t<_Range>, less<ranges::range_value_t<_Range>>, _Allocator>;
+set(from_range_t, _Range&&, _Allocator)
+ -> set<ranges::range_value_t<_Range>, less<ranges::range_value_t<_Range>>, _Allocator>;
# endif
template <class _Key, class _Allocator, class = enable_if_t<__is_allocator_v<_Allocator>>>
@@ -1394,9 +1392,8 @@ template <class _Key,
class _Allocator = allocator<_Key>,
class = enable_if_t<__is_allocator_v<_Allocator>>,
class = enable_if_t<!__is_allocator_v<_Compare>>>
-multiset(initializer_list<_Key>,
- _Compare = _Compare(),
- _Allocator = _Allocator()) -> multiset<_Key, _Compare, _Allocator>;
+multiset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
+ -> multiset<_Key, _Compare, _Allocator>;
template <class _InputIterator,
class _Allocator,
@@ -1407,9 +1404,8 @@ multiset(_InputIterator, _InputIterator, _Allocator)
# if _LIBCPP_STD_VER >= 23
template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator_v<_Allocator>>>
-multiset(from_range_t,
- _Range&&,
- _Allocator) -> multiset<ranges::range_value_t<_Range>, less<ranges::range_value_t<_Range>>, _Allocator>;
+multiset(from_range_t, _Range&&, _Allocator)
+ -> multiset<ranges::range_value_t<_Range>, less<ranges::range_value_t<_Range>>, _Allocator>;
# endif
template <class _Key, class _Allocator, class = enable_if_t<__is_allocator_v<_Allocator>>>
diff --git a/libcxx/include/stack b/libcxx/include/stack
index ec3de2d4f..fddfe4349 100644
--- a/libcxx/include/stack
+++ b/libcxx/include/stack
@@ -315,14 +315,12 @@ template <class _InputIterator,
class _Alloc,
__enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0,
__enable_if_t<__is_allocator_v<_Alloc>, int> = 0>
-stack(_InputIterator,
- _InputIterator,
- _Alloc) -> stack<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>;
+stack(_InputIterator, _InputIterator, _Alloc)
+ -> stack<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>;
template <ranges::input_range _Range, class _Alloc, __enable_if_t<__is_allocator_v<_Alloc>, int> = 0>
-stack(from_range_t,
- _Range&&,
- _Alloc) -> stack<ranges::range_value_t<_Range>, deque<ranges::range_value_t<_Range>, _Alloc>>;
+stack(from_range_t, _Range&&, _Alloc)
+ -> stack<ranges::range_value_t<_Range>, deque<ranges::range_value_t<_Range>, _Alloc>>;
# endif
diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map
index d19ed616c..31041e83b 100644
--- a/libcxx/include/unordered_map
+++ b/libcxx/include/unordered_map
@@ -2258,12 +2258,12 @@ template <class _Key,
class = enable_if_t<!is_integral<_Hash>::value>,
class = enable_if_t<!__is_allocator_v<_Pred>>,
class = enable_if_t<__is_allocator_v<_Allocator>>>
-unordered_multimap(
- initializer_list<pair<_Key, _Tp>>,
- typename allocator_traits<_Allocator>::size_type = 0,
- _Hash = _Hash(),
- _Pred = _Pred(),
- _Allocator = _Allocator()) -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>;
+unordered_multimap(initializer_list<pair<_Key, _Tp>>,
+ typename allocator_traits<_Allocator>::size_type = 0,
+ _Hash = _Hash(),
+ _Pred = _Pred(),
+ _Allocator = _Allocator())
+ -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>;
template <class _InputIterator,
class _Allocator,
diff --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set
index 02099cfa2..0268dd772 100644
--- a/libcxx/include/unordered_set
+++ b/libcxx/include/unordered_set
@@ -941,13 +941,13 @@ template <ranges::input_range _Range,
class = enable_if_t<!is_integral<_Hash>::value>,
class = enable_if_t<!__is_allocator_v<_Pred>>,
class = enable_if_t<__is_allocator_v<_Allocator>>>
-unordered_set(
- from_range_t,
- _Range&&,
- typename allocator_traits<_Allocator>::size_type = 0,
- _Hash = _Hash(),
- _Pred = _Pred(),
- _Allocator = _Allocator()) -> unordered_set<ranges::range_value_t<_Range>, _Hash, _Pred, _Allocator>; // C++23
+unordered_set(from_range_t,
+ _Range&&,
+ typename allocator_traits<_Allocator>::size_type = 0,
+ _Hash = _Hash(),
+ _Pred = _Pred(),
+ _Allocator = _Allocator())
+ -> unordered_set<ranges::range_value_t<_Range>, _Hash, _Pred, _Allocator>; // C++23
# endif
template <class _Tp,
diff --git a/libcxx/include/valarray b/libcxx/include/valarray
index 691634a8d..dac49ab2c 100644
--- a/libcxx/include/valarray
+++ b/libcxx/include/valarray
@@ -3161,9 +3161,7 @@ atan(const _Expr& __x) {
return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
}
-template <class _Expr1,
- class _Expr2,
- __enable_if_t<__is_val_expr_v<_Expr1> && __is_val_expr_v<_Expr2>, int> = 0>
+template <class _Expr1, class _Expr2, __enable_if_t<__is_val_expr_v<_Expr1> && __is_val_expr_v<_Expr2>, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
atan2(const _Expr1& __x, const _Expr2& __y) {
typedef typename _Expr1::value_type value_type;
diff --git a/libcxx/test/libcxx/utilities/utility/__is_inplace_index.pass.cpp b/libcxx/test/libcxx/utilities/utility/__is_inplace_index.pass.cpp
index c1439f795..b8e7f40eb 100644
--- a/libcxx/test/libcxx/utilities/utility/__is_inplace_index.pass.cpp
+++ b/libcxx/test/libcxx/utilities/utility/__is_inplace_index.pass.cpp
@@ -18,15 +18,15 @@ struct S {};
int main(int, char**) {
using I = std::in_place_index_t<0>;
- static_assert( std::__is_in_place_index_v<I>, "");
- static_assert( std::__is_in_place_index_v<const I>, "");
- static_assert( std::__is_in_place_index_v<const volatile I>, "");
- static_assert( std::__is_in_place_index_v<I&>, "");
- static_assert( std::__is_in_place_index_v<const I&>, "");
- static_assert( std::__is_in_place_index_v<const volatile I&>, "");
- static_assert( std::__is_in_place_index_v<I&&>, "");
- static_assert( std::__is_in_place_index_v<const I&&>, "");
- static_assert( std::__is_in_place_index_v<const volatile I&&>, "");
+ static_assert(std::__is_in_place_index_v<I>, "");
+ static_assert(std::__is_in_place_index_v<const I>, "");
+ static_assert(std::__is_in_place_index_v<const volatile I>, "");
+ static_assert(std::__is_in_place_index_v<I&>, "");
+ static_assert(std::__is_in_place_index_v<const I&>, "");
+ static_assert(std::__is_in_place_index_v<const volatile I&>, "");
+ static_assert(std::__is_in_place_index_v<I&&>, "");
+ static_assert(std::__is_in_place_index_v<const I&&>, "");
+ static_assert(std::__is_in_place_index_v<const volatile I&&>, "");
static_assert(!std::__is_in_place_index_v<std::in_place_type_t<int>>, "");
static_assert(!std::__is_in_place_index_v<std::in_place_t>, "");
static_assert(!std::__is_in_place_index_v<void>, "");
diff --git a/libcxx/test/libcxx/utilities/utility/__is_inplace_type.pass.cpp b/libcxx/test/libcxx/utilities/utility/__is_inplace_type.pass.cpp
index f5b7575e1..ae757c111 100644
--- a/libcxx/test/libcxx/utilities/utility/__is_inplace_type.pass.cpp
+++ b/libcxx/test/libcxx/utilities/utility/__is_inplace_type.pass.cpp
@@ -18,15 +18,15 @@ struct S {};
int main(int, char**) {
using T = std::in_place_type_t<int>;
- static_assert( std::__is_in_place_type_v<T>, "");
- static_assert( std::__is_in_place_type_v<const T>, "");
- static_assert( std::__is_in_place_type_v<const volatile T>, "");
- static_assert( std::__is_in_place_type_v<T&>, "");
- static_assert( std::__is_in_place_type_v<const T&>, "");
- static_assert( std::__is_in_place_type_v<const volatile T&>, "");
- static_assert( std::__is_in_place_type_v<T&&>, "");
- static_assert( std::__is_in_place_type_v<const T&&>, "");
- static_assert( std::__is_in_place_type_v<const volatile T&&>, "");
+ static_assert(std::__is_in_place_type_v<T>, "");
+ static_assert(std::__is_in_place_type_v<const T>, "");
+ static_assert(std::__is_in_place_type_v<const volatile T>, "");
+ static_assert(std::__is_in_place_type_v<T&>, "");
+ static_assert(std::__is_in_place_type_v<const T&>, "");
+ static_assert(std::__is_in_place_type_v<const volatile T&>, "");
+ static_assert(std::__is_in_place_type_v<T&&>, "");
+ static_assert(std::__is_in_place_type_v<const T&&>, "");
+ static_assert(std::__is_in_place_type_v<const volatile T&&>, "");
static_assert(!std::__is_in_place_type_v<std::in_place_index_t<0>>, "");
static_assert(!std::__is_in_place_type_v<std::in_place_t>, "");
static_assert(!std::__is_in_place_type_v<void>, "");
``````````
</details>
https://github.com/llvm/llvm-project/pull/139518
More information about the libcxx-commits
mailing list