[libcxx-commits] [libcxx] [libc++] Remove _If and use conditional_t instead (PR #96744)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jun 26 02:02:04 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Nikolas Klauser (philnik777)
<details>
<summary>Changes</summary>
`_If` and `conditional_t` now have the same definition. This simply removes one of the ways to spell the same thing.
---
Patch is 32.46 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/96744.diff
24 Files Affected:
- (modified) libcxx/include/__bit_reference (+1-1)
- (modified) libcxx/include/__expected/expected.h (+11-11)
- (modified) libcxx/include/__functional/bind.h (+6-4)
- (modified) libcxx/include/__iterator/common_iterator.h (+2-2)
- (modified) libcxx/include/__iterator/iterator_traits.h (+1-1)
- (modified) libcxx/include/__iterator/move_iterator.h (+6-6)
- (modified) libcxx/include/__iterator/reverse_iterator.h (+8-7)
- (modified) libcxx/include/__memory/shared_ptr.h (+7-6)
- (modified) libcxx/include/__pstl/dispatch.h (+3-3)
- (modified) libcxx/include/__ranges/dangling.h (+1-1)
- (modified) libcxx/include/__ranges/drop_view.h (+1-1)
- (modified) libcxx/include/__ranges/drop_while_view.h (+1-1)
- (modified) libcxx/include/__ranges/filter_view.h (+11-11)
- (modified) libcxx/include/__ranges/iota_view.h (+10-10)
- (modified) libcxx/include/__ranges/join_view.h (+17-16)
- (modified) libcxx/include/__ranges/lazy_split_view.h (+6-6)
- (modified) libcxx/include/__ranges/reverse_view.h (+1-1)
- (modified) libcxx/include/__ranges/subrange.h (+1-1)
- (modified) libcxx/include/__type_traits/conditional.h (+1-4)
- (modified) libcxx/include/__utility/forward_like.h (+2-2)
- (modified) libcxx/include/optional (+13-11)
- (modified) libcxx/include/tuple (+5-5)
- (modified) libcxx/include/variant (+2-2)
- (modified) libcxx/test/libcxx/utilities/meta/meta_base.pass.cpp (-5)
``````````diff
diff --git a/libcxx/include/__bit_reference b/libcxx/include/__bit_reference
index 606069d98be72..870b0c4dd0656 100644
--- a/libcxx/include/__bit_reference
+++ b/libcxx/include/__bit_reference
@@ -824,7 +824,7 @@ public:
// When _IsConst=true, the assignment operators are
// implicitly generated and trivial.
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator&
- operator=(const _If<_IsConst, struct __private_nat, __bit_iterator>& __it) {
+ operator=(const __conditional_t<_IsConst, struct __private_nat, __bit_iterator>& __it) {
__seg_ = __it.__seg_;
__ctz_ = __it.__ctz_;
return *this;
diff --git a/libcxx/include/__expected/expected.h b/libcxx/include/__expected/expected.h
index 0f994e297a877..776b6c2034e43 100644
--- a/libcxx/include/__expected/expected.h
+++ b/libcxx/include/__expected/expected.h
@@ -506,20 +506,20 @@ class expected : private __expected_base<_Tp, _Err> {
using __can_convert =
_And< is_constructible<_Tp, _UfQual>,
is_constructible<_Err, _OtherErrQual>,
- _If<_Not<is_same<remove_cv_t<_Tp>, bool>>::value,
- _And< _Not<is_constructible<_Tp, expected<_Up, _OtherErr>&>>,
- _Not<is_constructible<_Tp, expected<_Up, _OtherErr>>>,
- _Not<is_constructible<_Tp, const expected<_Up, _OtherErr>&>>,
- _Not<is_constructible<_Tp, const expected<_Up, _OtherErr>>>,
- _Not<is_convertible<expected<_Up, _OtherErr>&, _Tp>>,
- _Not<is_convertible<expected<_Up, _OtherErr>&&, _Tp>>,
- _Not<is_convertible<const expected<_Up, _OtherErr>&, _Tp>>,
- _Not<is_convertible<const expected<_Up, _OtherErr>&&, _Tp>>>,
- true_type>,
+ conditional_t<_Not<is_same<remove_cv_t<_Tp>, bool>>::value,
+ _And<_Not<is_constructible<_Tp, expected<_Up, _OtherErr>&>>,
+ _Not<is_constructible<_Tp, expected<_Up, _OtherErr>>>,
+ _Not<is_constructible<_Tp, const expected<_Up, _OtherErr>&>>,
+ _Not<is_constructible<_Tp, const expected<_Up, _OtherErr>>>,
+ _Not<is_convertible<expected<_Up, _OtherErr>&, _Tp>>,
+ _Not<is_convertible<expected<_Up, _OtherErr>&&, _Tp>>,
+ _Not<is_convertible<const expected<_Up, _OtherErr>&, _Tp>>,
+ _Not<is_convertible<const expected<_Up, _OtherErr>&&, _Tp>>>,
+ true_type>,
_Not<is_constructible<unexpected<_Err>, expected<_Up, _OtherErr>&>>,
_Not<is_constructible<unexpected<_Err>, expected<_Up, _OtherErr>>>,
_Not<is_constructible<unexpected<_Err>, const expected<_Up, _OtherErr>&>>,
- _Not<is_constructible<unexpected<_Err>, const expected<_Up, _OtherErr>>> >;
+ _Not<is_constructible<unexpected<_Err>, const expected<_Up, _OtherErr>>>>;
template <class _Func, class... _Args>
_LIBCPP_HIDE_FROM_ABI constexpr explicit expected(
diff --git a/libcxx/include/__functional/bind.h b/libcxx/include/__functional/bind.h
index b4f46441da507..3e8eccc3fa2e3 100644
--- a/libcxx/include/__functional/bind.h
+++ b/libcxx/include/__functional/bind.h
@@ -28,7 +28,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp>
struct is_bind_expression
- : _If< _IsSame<_Tp, __remove_cvref_t<_Tp> >::value, false_type, is_bind_expression<__remove_cvref_t<_Tp> > > {};
+ : __conditional_t<_IsSame<_Tp, __remove_cvref_t<_Tp> >::value,
+ false_type,
+ is_bind_expression<__remove_cvref_t<_Tp> > > {};
#if _LIBCPP_STD_VER >= 17
template <class _Tp>
@@ -37,9 +39,9 @@ inline constexpr bool is_bind_expression_v = is_bind_expression<_Tp>::value;
template <class _Tp>
struct is_placeholder
- : _If< _IsSame<_Tp, __remove_cvref_t<_Tp> >::value,
- integral_constant<int, 0>,
- is_placeholder<__remove_cvref_t<_Tp> > > {};
+ : __conditional_t<_IsSame<_Tp, __remove_cvref_t<_Tp> >::value,
+ integral_constant<int, 0>,
+ is_placeholder<__remove_cvref_t<_Tp> > > {};
#if _LIBCPP_STD_VER >= 17
template <class _Tp>
diff --git a/libcxx/include/__iterator/common_iterator.h b/libcxx/include/__iterator/common_iterator.h
index 199de2cc7337b..369425c7cd789 100644
--- a/libcxx/include/__iterator/common_iterator.h
+++ b/libcxx/include/__iterator/common_iterator.h
@@ -282,8 +282,8 @@ struct __arrow_type_or_void<_Iter, _Sent> {
template <input_iterator _Iter, class _Sent>
struct iterator_traits<common_iterator<_Iter, _Sent>> {
- using iterator_concept = _If<forward_iterator<_Iter>, forward_iterator_tag, input_iterator_tag>;
- using iterator_category = _If<__denotes_forward_iter<_Iter>, forward_iterator_tag, input_iterator_tag>;
+ using iterator_concept = __conditional_t<forward_iterator<_Iter>, forward_iterator_tag, input_iterator_tag>;
+ using iterator_category = __conditional_t<__denotes_forward_iter<_Iter>, forward_iterator_tag, input_iterator_tag>;
using pointer = typename __arrow_type_or_void<_Iter, _Sent>::type;
using value_type = iter_value_t<_Iter>;
using difference_type = iter_difference_t<_Iter>;
diff --git a/libcxx/include/__iterator/iterator_traits.h b/libcxx/include/__iterator/iterator_traits.h
index 11af9e301842c..d030c94f85b54 100644
--- a/libcxx/include/__iterator/iterator_traits.h
+++ b/libcxx/include/__iterator/iterator_traits.h
@@ -75,7 +75,7 @@ struct _LIBCPP_TEMPLATE_VIS contiguous_iterator_tag : public random_access_itera
template <class _Iter>
struct __iter_traits_cache {
- using type = _If< __is_primary_template<iterator_traits<_Iter> >::value, _Iter, iterator_traits<_Iter> >;
+ using type = __conditional_t<__is_primary_template<iterator_traits<_Iter> >::value, _Iter, iterator_traits<_Iter> >;
};
template <class _Iter>
using _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type;
diff --git a/libcxx/include/__iterator/move_iterator.h b/libcxx/include/__iterator/move_iterator.h
index c266022159a15..7884b5cb30b05 100644
--- a/libcxx/include/__iterator/move_iterator.h
+++ b/libcxx/include/__iterator/move_iterator.h
@@ -52,9 +52,9 @@ template <class _Iter>
requires requires { typename iterator_traits<_Iter>::iterator_category; }
struct __move_iter_category_base<_Iter> {
using iterator_category =
- _If< derived_from<typename iterator_traits<_Iter>::iterator_category, random_access_iterator_tag>,
- random_access_iterator_tag,
- typename iterator_traits<_Iter>::iterator_category >;
+ __conditional_t<derived_from<typename iterator_traits<_Iter>::iterator_category, random_access_iterator_tag>,
+ random_access_iterator_tag,
+ typename iterator_traits<_Iter>::iterator_category>;
};
template <class _Iter, class _Sent>
@@ -96,9 +96,9 @@ class _LIBCPP_TEMPLATE_VIS move_iterator
using reference = iter_rvalue_reference_t<_Iter>;
#else
typedef _Iter iterator_type;
- typedef _If< __has_random_access_iterator_category<_Iter>::value,
- random_access_iterator_tag,
- typename iterator_traits<_Iter>::iterator_category >
+ typedef __conditional_t<__has_random_access_iterator_category<_Iter>::value,
+ random_access_iterator_tag,
+ typename iterator_traits<_Iter>::iterator_category >
iterator_category;
typedef typename iterator_traits<iterator_type>::value_type value_type;
typedef typename iterator_traits<iterator_type>::difference_type difference_type;
diff --git a/libcxx/include/__iterator/reverse_iterator.h b/libcxx/include/__iterator/reverse_iterator.h
index 50c0f21eaa286..f2f123806b814 100644
--- a/libcxx/include/__iterator/reverse_iterator.h
+++ b/libcxx/include/__iterator/reverse_iterator.h
@@ -76,15 +76,16 @@ class _LIBCPP_TEMPLATE_VIS reverse_iterator
using iterator_type = _Iter;
using iterator_category =
- _If<__has_random_access_iterator_category<_Iter>::value,
- random_access_iterator_tag,
- typename iterator_traits<_Iter>::iterator_category>;
+ __conditional_t<__has_random_access_iterator_category<_Iter>::value,
+ random_access_iterator_tag,
+ typename iterator_traits<_Iter>::iterator_category>;
using pointer = typename iterator_traits<_Iter>::pointer;
#if _LIBCPP_STD_VER >= 20
- using iterator_concept = _If<random_access_iterator<_Iter>, random_access_iterator_tag, bidirectional_iterator_tag>;
- using value_type = iter_value_t<_Iter>;
- using difference_type = iter_difference_t<_Iter>;
- using reference = iter_reference_t<_Iter>;
+ using iterator_concept =
+ conditional_t<random_access_iterator<_Iter>, random_access_iterator_tag, bidirectional_iterator_tag>;
+ using value_type = iter_value_t<_Iter>;
+ using difference_type = iter_difference_t<_Iter>;
+ using reference = iter_reference_t<_Iter>;
#else
using value_type = typename iterator_traits<_Iter>::value_type;
using difference_type = typename iterator_traits<_Iter>::difference_type;
diff --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h
index d487e4fbe3a95..f48428165f06d 100644
--- a/libcxx/include/__memory/shared_ptr.h
+++ b/libcxx/include/__memory/shared_ptr.h
@@ -437,17 +437,18 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT : __ptr_(nullptr), __cntrl_(nullptr) {}
- template <class _Yp,
- __enable_if_t< _And< __raw_pointer_compatible_with<_Yp, _Tp>
+ template <
+ class _Yp,
+ __enable_if_t< _And< __raw_pointer_compatible_with<_Yp, _Tp>
// In C++03 we get errors when trying to do SFINAE with the
// delete operator, so we always pretend that it's deletable.
// The same happens on GCC.
#if !defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_COMPILER_GCC)
- ,
- _If<is_array<_Tp>::value, __is_array_deletable<_Yp*>, __is_deletable<_Yp*> >
+ ,
+ __conditional_t<is_array<_Tp>::value, __is_array_deletable<_Yp*>, __is_deletable<_Yp*> >
#endif
- >::value,
- int> = 0>
+ >::value,
+ int> = 0>
_LIBCPP_HIDE_FROM_ABI explicit shared_ptr(_Yp* __p) : __ptr_(__p) {
unique_ptr<_Yp> __hold(__p);
typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
diff --git a/libcxx/include/__pstl/dispatch.h b/libcxx/include/__pstl/dispatch.h
index 5e903f7524fe9..4fffcc263c5ed 100644
--- a/libcxx/include/__pstl/dispatch.h
+++ b/libcxx/include/__pstl/dispatch.h
@@ -51,9 +51,9 @@ struct __find_first_implemented<_Algorithm, __backend_configuration<>, _Executio
template <template <class, class> class _Algorithm, class _B1, class... _Bn, class _ExecutionPolicy>
struct __find_first_implemented<_Algorithm, __backend_configuration<_B1, _Bn...>, _ExecutionPolicy>
- : _If<__is_implemented_v<_Algorithm, _B1, _ExecutionPolicy>,
- __type_identity<_Algorithm<_B1, _ExecutionPolicy>>,
- __find_first_implemented<_Algorithm, __backend_configuration<_Bn...>, _ExecutionPolicy> > {};
+ : __conditional_t<__is_implemented_v<_Algorithm, _B1, _ExecutionPolicy>,
+ __type_identity<_Algorithm<_B1, _ExecutionPolicy>>,
+ __find_first_implemented<_Algorithm, __backend_configuration<_Bn...>, _ExecutionPolicy>> {};
template <template <class, class> class _Algorithm, class _BackendConfiguration, class _ExecutionPolicy>
using __dispatch = typename __find_first_implemented<_Algorithm, _BackendConfiguration, _ExecutionPolicy>::type;
diff --git a/libcxx/include/__ranges/dangling.h b/libcxx/include/__ranges/dangling.h
index 613084d5fb9fc..6e7db6b012aa2 100644
--- a/libcxx/include/__ranges/dangling.h
+++ b/libcxx/include/__ranges/dangling.h
@@ -30,7 +30,7 @@ struct dangling {
};
template <range _Rp>
-using borrowed_iterator_t = _If<borrowed_range<_Rp>, iterator_t<_Rp>, dangling>;
+using borrowed_iterator_t = conditional_t<borrowed_range<_Rp>, iterator_t<_Rp>, dangling>;
// borrowed_subrange_t defined in <__ranges/subrange.h>
} // namespace ranges
diff --git a/libcxx/include/__ranges/drop_view.h b/libcxx/include/__ranges/drop_view.h
index 853e22a402cad..1296f981817c5 100644
--- a/libcxx/include/__ranges/drop_view.h
+++ b/libcxx/include/__ranges/drop_view.h
@@ -64,7 +64,7 @@ class drop_view : public view_interface<drop_view<_View>> {
// Note: drop_view<input-range>::begin() is still trivially amortized O(1) because
// one can't call begin() on it more than once.
static constexpr bool _UseCache = forward_range<_View> && !(random_access_range<_View> && sized_range<_View>);
- using _Cache = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
+ using _Cache = conditional_t<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
_LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache();
range_difference_t<_View> __count_ = 0;
_View __base_ = _View();
diff --git a/libcxx/include/__ranges/drop_while_view.h b/libcxx/include/__ranges/drop_while_view.h
index 92f48bd0ecfba..73454f9a52b30 100644
--- a/libcxx/include/__ranges/drop_while_view.h
+++ b/libcxx/include/__ranges/drop_while_view.h
@@ -90,7 +90,7 @@ class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS drop_while_view : public view_interfa
_LIBCPP_NO_UNIQUE_ADDRESS __movable_box<_Pred> __pred_;
static constexpr bool _UseCache = forward_range<_View>;
- using _Cache = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
+ using _Cache = conditional_t<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
_LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache();
};
diff --git a/libcxx/include/__ranges/filter_view.h b/libcxx/include/__ranges/filter_view.h
index 5b938dd4c16e1..3fb2edeee260e 100644
--- a/libcxx/include/__ranges/filter_view.h
+++ b/libcxx/include/__ranges/filter_view.h
@@ -61,7 +61,7 @@ class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS filter_view : public view_interface<f
// We cache the result of begin() to allow providing an amortized O(1) begin() whenever
// the underlying range is at least a forward_range.
static constexpr bool _UseCache = forward_range<_View>;
- using _Cache = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
+ using _Cache = conditional_t<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
_LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache();
class __iterator;
@@ -117,11 +117,11 @@ template <forward_range _View>
struct __filter_iterator_category<_View> {
using _Cat = typename iterator_traits<iterator_t<_View>>::iterator_category;
using iterator_category =
- _If<derived_from<_Cat, bidirectional_iterator_tag>,
- bidirectional_iterator_tag,
- _If<derived_from<_Cat, forward_iterator_tag>,
- forward_iterator_tag,
- /* else */ _Cat >>;
+ conditional_t<derived_from<_Cat, bidirectional_iterator_tag>,
+ bidirectional_iterator_tag,
+ conditional_t<derived_from<_Cat, forward_iterator_tag>,
+ forward_iterator_tag,
+ /* else */ _Cat >>;
};
template <input_range _View, indirect_unary_predicate<iterator_t<_View>> _Pred>
@@ -132,11 +132,11 @@ class filter_view<_View, _Pred>::__iterator : public __filter_iterator_category<
_LIBCPP_NO_UNIQUE_ADDRESS filter_view* __parent_ = nullptr;
using iterator_concept =
- _If<bidirectional_range<_View>,
- bidirectional_iterator_tag,
- _If<forward_range<_View>,
- forward_iterator_tag,
- /* else */ input_iterator_tag >>;
+ conditional_t<bidirectional_range<_View>,
+ bidirectional_iterator_tag,
+ conditional_t<forward_range<_View>,
+ forward_iterator_tag,
+ /* else */ input_iterator_tag >>;
// using iterator_category = inherited;
using value_type = range_value_t<_View>;
using difference_type = range_difference_t<_View>;
diff --git a/libcxx/include/__ranges/iota_view.h b/libcxx/include/__ranges/iota_view.h
index 9e6f724241ccf..b5d909664d2bf 100644
--- a/libcxx/include/__ranges/iota_view.h
+++ b/libcxx/include/__ranges/iota_view.h
@@ -70,9 +70,9 @@ struct __get_wider_signed {
template <class _Start>
using _IotaDiffT =
- typename _If< (!integral<_Start> || sizeof(iter_difference_t<_Start>) > sizeof(_Start)),
- type_identity<iter_difference_t<_Start>>,
- __get_wider_signed<_Start> >::type;
+ typename conditional_t<(!integral<_Start> || sizeof(iter_difference_t<_Start>) > sizeof(_Start)),
+ type_identity<iter_difference_t<_Start>>,
+ __get_wider_signed<_Start> >::type;
template <class _Iter>
concept __decrementable = incrementable<_Iter> && requires(_Iter __i) {
@@ -107,13 +107,13 @@ class iota_view : public view_interface<iota_view<_Start, _BoundSentinel>> {
friend class iota_view;
using iterator_concept =
- _If<__advanceable<_Start>,
- random_access_iterator_tag,
- _If<__decrementable<_Start>,
- bidirectional_iterator_tag,
- _If<incrementable<_Start>,
- forward_iterator_tag,
- /*Else*/ input_iterator_tag>>>;
+ conditional_t<__advanceable<_Start>,
+ random_access_iterator_tag,
+ conditional_t<__decrementable<_Start>,
+ bidirectional_iterator_tag,
+ conditional_t<incrementable<_Start>,
+ forward_iterator_tag,
+ /*Else*/ input_iterator_tag>>>;
using value_type = _Start;
using difference_type = _IotaDiffT<_Start>;
diff --git a/libcxx/include/__ranges/join_view.h b/libcxx/include/__ranges/join_view.h
index 9c2c77995539b..a35c2a0e79be1 100644
--- a/libcxx/include/__ranges/join_view.h
+++ b/libcxx/include/__ranges/join_view.h
@@ -58,13 +58,13 @@ struct __join_view_iterator_category<_View> {
using _OuterC = typename iterator_traits<iterator_t<_View>>::iterator_category;
using _InnerC = typename iterator_traits<iterator_t<range_reference_t<_View>>>::iterator_category;
- using iterator_category =
- _If< derived_from<_OuterC, bidirectional_iterator_tag> && derived_from<_InnerC, bidirectional_iterator_tag> &&
- common_range<range_reference_t<_View>>,
- bidirectional_iterator_tag,
- _If< derived_from<_OuterC, forward_iterator_tag> && derived_from<_InnerC, forward_iterator_tag>,
- forward_iterator_tag,
- input_iterator_tag > >;
+ using iterator_category = __conditional_t<
+ derived_from<_OuterC, bidirectional_iterator_tag> && derived_from<_InnerC, bidirectional_iterator_tag> &&
+ common_range<range_reference_t<_View>>,
+ bidirectional_iterator_tag,
+ __conditional_t<derived_from<_OuterC, forward_iterator_tag> && derived_from<_InnerC, forward_iterator_tag>,
+ forward_iterator_tag,
+ input_iterator_tag > >;
};
template <input_range _View>
@@ -85,11 +85,12 @@ class join_view : public view_interface<join_view<_View>> {
_LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
static constexpr bool _UseOuterCache = !forward_range<_View>;
- using _OuterCache = _If<_UseOuterCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
+ using _OuterCache = conditional_t<_UseOuterCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
_LIBCPP_NO_UNIQU...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/96744
More information about the libcxx-commits
mailing list