Skip to content

[libc++] Remove _If and use conditional_t instead #96744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libcxx/include/__bit_reference
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 11 additions & 11 deletions libcxx/include/__expected/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 6 additions & 4 deletions libcxx/include/__functional/bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__iterator/common_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__iterator/iterator_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions libcxx/include/__iterator/move_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 8 additions & 7 deletions libcxx/include/__iterator/reverse_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 7 additions & 6 deletions libcxx/include/__memory/shared_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__pstl/dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__ranges/dangling.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__ranges/drop_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__ranges/drop_while_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down
22 changes: 11 additions & 11 deletions libcxx/include/__ranges/filter_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>
Expand All @@ -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>;
Expand Down
20 changes: 10 additions & 10 deletions libcxx/include/__ranges/iota_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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>;
Expand Down
33 changes: 17 additions & 16 deletions libcxx/include/__ranges/join_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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_UNIQUE_ADDRESS _OuterCache __outer_;

static constexpr bool _UseInnerCache = !is_reference_v<_InnerRange>;
using _InnerCache = _If<_UseInnerCache, __non_propagating_cache<remove_cvref_t<_InnerRange>>, __empty_cache>;
using _InnerCache =
conditional_t<_UseInnerCache, __non_propagating_cache<remove_cvref_t<_InnerRange>>, __empty_cache>;
_LIBCPP_NO_UNIQUE_ADDRESS _InnerCache __inner_;

public:
Expand Down Expand Up @@ -201,7 +202,7 @@ struct join_view<_View>::__iterator final : public __join_view_iterator_category
static constexpr bool __ref_is_glvalue = is_reference_v<range_reference_t<_Base>>;

static constexpr bool _OuterPresent = forward_range<_Base>;
using _OuterType = _If<_OuterPresent, _Outer, std::__empty>;
using _OuterType = conditional_t<_OuterPresent, _Outer, std::__empty>;
_LIBCPP_NO_UNIQUE_ADDRESS _OuterType __outer_ = _OuterType();

optional<_Inner> __inner_;
Expand Down Expand Up @@ -258,12 +259,12 @@ struct join_view<_View>::__iterator final : public __join_view_iterator_category

public:
using iterator_concept =
_If< __ref_is_glvalue && bidirectional_range<_Base> && bidirectional_range<range_reference_t<_Base>> &&
common_range<range_reference_t<_Base>>,
bidirectional_iterator_tag,
_If< __ref_is_glvalue && forward_range<_Base> && forward_range<range_reference_t<_Base>>,
forward_iterator_tag,
input_iterator_tag > >;
conditional_t<__ref_is_glvalue && bidirectional_range<_Base> && bidirectional_range<range_reference_t<_Base>> &&
common_range<range_reference_t<_Base>>,
bidirectional_iterator_tag,
conditional_t<__ref_is_glvalue && forward_range<_Base> && forward_range<range_reference_t<_Base>>,
forward_iterator_tag,
input_iterator_tag>>;

using value_type = range_value_t<range_reference_t<_Base>>;

Expand Down
Loading
Loading