Skip to content

[libc++][NFC] Make __desugars_to a variable template and rename the header to desugars_to.h #87337

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

Merged
merged 1 commit into from
Apr 4, 2024
Merged
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/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ set(files
__type_traits/datasizeof.h
__type_traits/decay.h
__type_traits/dependent_type.h
__type_traits/desugars_to.h
__type_traits/disjunction.h
__type_traits/enable_if.h
__type_traits/extent.h
Expand Down Expand Up @@ -821,7 +822,6 @@ set(files
__type_traits/nat.h
__type_traits/negation.h
__type_traits/noexcept_move_assign_container.h
__type_traits/operation_traits.h
__type_traits/promote.h
__type_traits/rank.h
__type_traits/remove_all_extents.h
Expand Down
5 changes: 2 additions & 3 deletions libcxx/include/__algorithm/comp.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#define _LIBCPP___ALGORITHM_COMP_H

#include <__config>
#include <__type_traits/integral_constant.h>
#include <__type_traits/operation_traits.h>
#include <__type_traits/desugars_to.h>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
Expand All @@ -27,7 +26,7 @@ struct __equal_to {
};

template <class _Tp, class _Up>
struct __desugars_to<__equal_tag, __equal_to, _Tp, _Up> : true_type {};
inline const bool __desugars_to_v<__equal_tag, __equal_to, _Tp, _Up> = true;

// The definition is required because __less is part of the ABI, but it's empty
// because all comparisons should be transparent.
Expand Down
7 changes: 3 additions & 4 deletions libcxx/include/__algorithm/equal.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
#include <__iterator/distance.h>
#include <__iterator/iterator_traits.h>
#include <__string/constexpr_c_functions.h>
#include <__type_traits/desugars_to.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/integral_constant.h>
#include <__type_traits/is_constant_evaluated.h>
#include <__type_traits/is_equality_comparable.h>
#include <__type_traits/is_volatile.h>
#include <__type_traits/operation_traits.h>
#include <__utility/move.h>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Expand All @@ -47,7 +46,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 boo
template <class _Tp,
class _Up,
class _BinaryPredicate,
__enable_if_t<__desugars_to<__equal_tag, _BinaryPredicate, _Tp, _Up>::value && !is_volatile<_Tp>::value &&
__enable_if_t<__desugars_to_v<__equal_tag, _BinaryPredicate, _Tp, _Up> && !is_volatile<_Tp>::value &&
!is_volatile<_Up>::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
Expand Down Expand Up @@ -87,7 +86,7 @@ template <class _Tp,
class _Pred,
class _Proj1,
class _Proj2,
__enable_if_t<__desugars_to<__equal_tag, _Pred, _Tp, _Up>::value && __is_identity<_Proj1>::value &&
__enable_if_t<__desugars_to_v<__equal_tag, _Pred, _Tp, _Up> && __is_identity<_Proj1>::value &&
__is_identity<_Proj2>::value && !is_volatile<_Tp>::value && !is_volatile<_Up>::value &&
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
int> = 0>
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__algorithm/mismatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#include <__algorithm/unwrap_iter.h>
#include <__config>
#include <__functional/identity.h>
#include <__type_traits/desugars_to.h>
#include <__type_traits/invoke.h>
#include <__type_traits/is_constant_evaluated.h>
#include <__type_traits/is_equality_comparable.h>
#include <__type_traits/is_integral.h>
#include <__type_traits/operation_traits.h>
#include <__utility/move.h>
#include <__utility/pair.h>
#include <__utility/unreachable.h>
Expand Down Expand Up @@ -59,7 +59,7 @@ template <class _Tp,
class _Pred,
class _Proj1,
class _Proj2,
__enable_if_t<is_integral<_Tp>::value && __desugars_to<__equal_tag, _Pred, _Tp, _Tp>::value &&
__enable_if_t<is_integral<_Tp>::value && __desugars_to_v<__equal_tag, _Pred, _Tp, _Tp> &&
__is_identity<_Proj1>::value && __is_identity<_Proj2>::value,
int> = 0>
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include <__iterator/concepts.h>
#include <__iterator/iterator_traits.h>
#include <__numeric/transform_reduce.h>
#include <__type_traits/desugars_to.h>
#include <__type_traits/is_arithmetic.h>
#include <__type_traits/is_execution_policy.h>
#include <__type_traits/operation_traits.h>
#include <__utility/move.h>
#include <new>
#include <optional>
Expand All @@ -37,7 +37,7 @@ template <typename _DifferenceType,
typename _BinaryOperation,
typename _UnaryOperation,
typename _UnaryResult = invoke_result_t<_UnaryOperation, _DifferenceType>,
__enable_if_t<__desugars_to<__plus_tag, _BinaryOperation, _Tp, _UnaryResult>::value && is_arithmetic_v<_Tp> &&
__enable_if_t<__desugars_to_v<__plus_tag, _BinaryOperation, _Tp, _UnaryResult> && is_arithmetic_v<_Tp> &&
is_arithmetic_v<_UnaryResult>,
int> = 0>
_LIBCPP_HIDE_FROM_ABI _Tp
Expand All @@ -53,8 +53,8 @@ template <typename _Size,
typename _BinaryOperation,
typename _UnaryOperation,
typename _UnaryResult = invoke_result_t<_UnaryOperation, _Size>,
__enable_if_t<!(__desugars_to<__plus_tag, _BinaryOperation, _Tp, _UnaryResult>::value &&
is_arithmetic_v<_Tp> && is_arithmetic_v<_UnaryResult>),
__enable_if_t<!(__desugars_to_v<__plus_tag, _BinaryOperation, _Tp, _UnaryResult> && is_arithmetic_v<_Tp> &&
is_arithmetic_v<_UnaryResult>),
int> = 0>
_LIBCPP_HIDE_FROM_ABI _Tp
__simd_transform_reduce(_Size __n, _Tp __init, _BinaryOperation __binary_op, _UnaryOperation __f) noexcept {
Expand Down
11 changes: 5 additions & 6 deletions libcxx/include/__functional/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
#include <__config>
#include <__functional/binary_function.h>
#include <__functional/unary_function.h>
#include <__type_traits/integral_constant.h>
#include <__type_traits/operation_traits.h>
#include <__type_traits/desugars_to.h>
#include <__utility/forward.h>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Expand All @@ -41,10 +40,10 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(plus);
// The non-transparent std::plus specialization is only equivalent to a raw plus
// operator when we don't perform an implicit conversion when calling it.
template <class _Tp>
struct __desugars_to<__plus_tag, plus<_Tp>, _Tp, _Tp> : true_type {};
inline const bool __desugars_to_v<__plus_tag, plus<_Tp>, _Tp, _Tp> = true;

template <class _Tp, class _Up>
struct __desugars_to<__plus_tag, plus<void>, _Tp, _Up> : true_type {};
inline const bool __desugars_to_v<__plus_tag, plus<void>, _Tp, _Up> = true;

#if _LIBCPP_STD_VER >= 14
template <>
Expand Down Expand Up @@ -315,11 +314,11 @@ struct _LIBCPP_TEMPLATE_VIS equal_to<void> {
// The non-transparent std::equal_to specialization is only equivalent to a raw equality
// comparison when we don't perform an implicit conversion when calling it.
template <class _Tp>
struct __desugars_to<__equal_tag, equal_to<_Tp>, _Tp, _Tp> : true_type {};
inline const bool __desugars_to_v<__equal_tag, equal_to<_Tp>, _Tp, _Tp> = true;

// In the transparent case, we do not enforce that
template <class _Tp, class _Up>
struct __desugars_to<__equal_tag, equal_to<void>, _Tp, _Up> : true_type {};
inline const bool __desugars_to_v<__equal_tag, equal_to<void>, _Tp, _Up> = true;

#if _LIBCPP_STD_VER >= 14
template <class _Tp = void>
Expand Down
5 changes: 2 additions & 3 deletions libcxx/include/__functional/ranges_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
#include <__concepts/equality_comparable.h>
#include <__concepts/totally_ordered.h>
#include <__config>
#include <__type_traits/integral_constant.h>
#include <__type_traits/operation_traits.h>
#include <__type_traits/desugars_to.h>
#include <__utility/forward.h>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Expand Down Expand Up @@ -98,7 +97,7 @@ struct greater_equal {
// For ranges we do not require that the types on each side of the equality
// operator are of the same type
template <class _Tp, class _Up>
struct __desugars_to<__equal_tag, ranges::equal_to, _Tp, _Up> : true_type {};
inline const bool __desugars_to_v<__equal_tag, ranges::equal_to, _Tp, _Up> = true;

#endif // _LIBCPP_STD_VER >= 20

Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__numeric/pstl_transform_reduce.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ _LIBCPP_HIDE_FROM_ABI _Tp transform_reduce(
}

// This overload doesn't get a customization point because it's trivial to detect (through e.g.
// __desugars_to) when specializing the more general variant, which should always be preferred
// __desugars_to_v) when specializing the more general variant, which should always be preferred
template <class _ExecutionPolicy,
class _ForwardIterator1,
class _ForwardIterator2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___TYPE_TRAITS_OPERATION_TRAITS_H
#define _LIBCPP___TYPE_TRAITS_OPERATION_TRAITS_H
#ifndef _LIBCPP___TYPE_TRAITS_DESUGARS_TO_H
#define _LIBCPP___TYPE_TRAITS_DESUGARS_TO_H

#include <__config>
#include <__type_traits/integral_constant.h>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
Expand All @@ -33,8 +32,8 @@ struct __plus_tag {};
// predicate being passed is actually going to call a builtin operator, or has
// some specific semantics.
template <class _CanonicalTag, class _Operation, class... _Args>
struct __desugars_to : false_type {};
inline const bool __desugars_to_v = false;

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___TYPE_TRAITS_OPERATION_TRAITS_H
#endif // _LIBCPP___TYPE_TRAITS_DESUGARS_TO_H
2 changes: 1 addition & 1 deletion libcxx/include/libcxx.imp
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@
{ include: [ "<__type_traits/datasizeof.h>", "private", "<type_traits>", "public" ] },
{ include: [ "<__type_traits/decay.h>", "private", "<type_traits>", "public" ] },
{ include: [ "<__type_traits/dependent_type.h>", "private", "<type_traits>", "public" ] },
{ include: [ "<__type_traits/desugars_to.h>", "private", "<type_traits>", "public" ] },
{ include: [ "<__type_traits/disjunction.h>", "private", "<type_traits>", "public" ] },
{ include: [ "<__type_traits/enable_if.h>", "private", "<type_traits>", "public" ] },
{ include: [ "<__type_traits/extent.h>", "private", "<type_traits>", "public" ] },
Expand Down Expand Up @@ -817,7 +818,6 @@
{ include: [ "<__type_traits/nat.h>", "private", "<type_traits>", "public" ] },
{ include: [ "<__type_traits/negation.h>", "private", "<type_traits>", "public" ] },
{ include: [ "<__type_traits/noexcept_move_assign_container.h>", "private", "<type_traits>", "public" ] },
{ include: [ "<__type_traits/operation_traits.h>", "private", "<type_traits>", "public" ] },
{ include: [ "<__type_traits/promote.h>", "private", "<type_traits>", "public" ] },
{ include: [ "<__type_traits/rank.h>", "private", "<type_traits>", "public" ] },
{ include: [ "<__type_traits/remove_all_extents.h>", "private", "<type_traits>", "public" ] },
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,7 @@ module std_private_type_traits_decay [system
export std_private_type_traits_add_pointer
}
module std_private_type_traits_dependent_type [system] { header "__type_traits/dependent_type.h" }
module std_private_type_traits_desugars_to [system] { header "__type_traits/desugars_to.h" }
module std_private_type_traits_disjunction [system] { header "__type_traits/disjunction.h" }
module std_private_type_traits_enable_if [system] { header "__type_traits/enable_if.h" }
module std_private_type_traits_extent [system] { header "__type_traits/extent.h" }
Expand Down Expand Up @@ -2013,7 +2014,6 @@ module std_private_type_traits_maybe_const [system
module std_private_type_traits_nat [system] { header "__type_traits/nat.h" }
module std_private_type_traits_negation [system] { header "__type_traits/negation.h" }
module std_private_type_traits_noexcept_move_assign_container [system] { header "__type_traits/noexcept_move_assign_container.h" }
module std_private_type_traits_operation_traits [system] { header "__type_traits/operation_traits.h" }
module std_private_type_traits_promote [system] { header "__type_traits/promote.h" }
module std_private_type_traits_rank [system] { header "__type_traits/rank.h" }
module std_private_type_traits_remove_all_extents [system] { header "__type_traits/remove_all_extents.h" }
Expand Down