Skip to content

Commit bd62875

Browse files
committed
Fixup a few things. In particular I removed the test since I don't think it was testing anything new, and in fact I failed to write a reproducer for the transform_reduce _UnaryResult thing.
1 parent 56dbdd3 commit bd62875

File tree

7 files changed

+38
-93
lines changed

7 files changed

+38
-93
lines changed

libcxx/include/__algorithm/comp.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define _LIBCPP___ALGORITHM_COMP_H
1111

1212
#include <__config>
13-
#include <__functional/operations.h>
1413
#include <__type_traits/integral_constant.h>
1514
#include <__type_traits/operation_traits.h>
1615

@@ -27,8 +26,8 @@ struct __equal_to {
2726
}
2827
};
2928

30-
template <>
31-
struct __desugars_to<__equal_to, equal_to<void> > : true_type {};
29+
template <class _Tp, class _Up>
30+
struct __desugars_to<__equal_tag, __equal_to, _Tp, _Up> : true_type {};
3231

3332
// The definition is required because __less is part of the ABI, but it's empty
3433
// because all comparisons should be transparent.

libcxx/include/__algorithm/equal.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <__config>
1616
#include <__functional/identity.h>
1717
#include <__functional/invoke.h>
18-
#include <__functional/operations.h>
1918
#include <__iterator/distance.h>
2019
#include <__iterator/iterator_traits.h>
2120
#include <__string/constexpr_c_functions.h>
@@ -42,12 +41,12 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 boo
4241
return true;
4342
}
4443

45-
template < class _Tp,
46-
class _Up,
47-
class _BinaryPredicate,
48-
__enable_if_t<__desugars_to<__equal_tag, _BinaryPredicate, _Tp, _Up>::value && !is_volatile<_Tp>::value &&
49-
!is_volatile<_Up>::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
50-
int> = 0>
44+
template <class _Tp,
45+
class _Up,
46+
class _BinaryPredicate,
47+
__enable_if_t<__desugars_to<__equal_tag, _BinaryPredicate, _Tp, _Up>::value && !is_volatile<_Tp>::value &&
48+
!is_volatile<_Up>::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
49+
int> = 0>
5150
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
5251
__equal_iter_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _BinaryPredicate&) {
5352
return std::__constexpr_memcmp_equal(__first1, __first2, __element_count(__last1 - __first1));

libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
1313
#include <__config>
14-
#include <__functional/operations.h>
1514
#include <__iterator/concepts.h>
1615
#include <__iterator/iterator_traits.h>
1716
#include <__numeric/transform_reduce.h>
@@ -30,13 +29,14 @@
3029

3130
_LIBCPP_BEGIN_NAMESPACE_STD
3231

33-
template < typename _DifferenceType,
34-
typename _Tp,
35-
typename _BinaryOperation,
36-
typename _UnaryOperation,
37-
typename _UnaryResult = invoke_result_t<_UnaryOperation, _DifferenceType>,
38-
__enable_if_t<__desugars_to<__plus_tag, _BinaryOperation, _Tp, _UnaryResult>::value && is_arithmetic_v<_Tp>,
39-
int> = 0>
32+
template <typename _DifferenceType,
33+
typename _Tp,
34+
typename _BinaryOperation,
35+
typename _UnaryOperation,
36+
typename _UnaryResult = invoke_result_t<_UnaryOperation, _DifferenceType>,
37+
__enable_if_t<__desugars_to<__plus_tag, _BinaryOperation, _Tp, _UnaryResult>::value && is_arithmetic_v<_Tp> &&
38+
is_arithmetic_v<_UnaryResult>,
39+
int> = 0>
4040
_LIBCPP_HIDE_FROM_ABI _Tp
4141
__simd_transform_reduce(_DifferenceType __n, _Tp __init, _BinaryOperation, _UnaryOperation __f) noexcept {
4242
_PSTL_PRAGMA_SIMD_REDUCTION(+ : __init)
@@ -45,14 +45,14 @@ __simd_transform_reduce(_DifferenceType __n, _Tp __init, _BinaryOperation, _Unar
4545
return __init;
4646
}
4747

48-
template <
49-
typename _Size,
50-
typename _Tp,
51-
typename _BinaryOperation,
52-
typename _UnaryOperation,
53-
typename _UnaryResult = invoke_result_t<_UnaryOperation, _Size>,
54-
__enable_if_t<!(__desugars_to<__plus_tag, _BinaryOperation, _Tp, _UnaryResult>::value && is_arithmetic_v<_Tp>),
55-
int> = 0>
48+
template <typename _Size,
49+
typename _Tp,
50+
typename _BinaryOperation,
51+
typename _UnaryOperation,
52+
typename _UnaryResult = invoke_result_t<_UnaryOperation, _Size>,
53+
__enable_if_t<!(__desugars_to<__plus_tag, _BinaryOperation, _Tp, _UnaryResult>::value &&
54+
is_arithmetic_v<_Tp> && is_arithmetic_v<_UnaryResult>),
55+
int> = 0>
5656
_LIBCPP_HIDE_FROM_ABI _Tp
5757
__simd_transform_reduce(_Size __n, _Tp __init, _BinaryOperation __binary_op, _UnaryOperation __f) noexcept {
5858
const _Size __block_size = __lane_size / sizeof(_Tp);

libcxx/include/__functional/operations.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,13 @@ struct _LIBCPP_TEMPLATE_VIS plus
4040
};
4141
_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(plus);
4242

43-
// For the typed version of plus, we require that the left- and right-hand
44-
// side of the plus operator matches
43+
// The non-transparent std::plus specialization is only equivalent to a raw plus
44+
// operator when we don't perform an implicit conversion when calling it.
4545
template <class _Tp>
4646
struct __desugars_to<__plus_tag, plus<_Tp>, _Tp, _Tp> : true_type {};
4747

48-
#if _LIBCPP_STD_VER >= 14
49-
// In the transparent case, we do not enforce that
5048
template <class _Tp, class _Up>
5149
struct __desugars_to<__plus_tag, plus<void>, _Tp, _Up> : true_type {};
52-
#endif
5350

5451
#if _LIBCPP_STD_VER >= 14
5552
template <>
@@ -354,16 +351,14 @@ struct _LIBCPP_TEMPLATE_VIS equal_to<void>
354351
};
355352
#endif
356353

357-
// For the typed version of equal_to, we require that the left- and right-hand
358-
// side of the equality operator matches
354+
// The non-transparent std::equal_to specialization is only equivalent to a raw equality
355+
// comparison when we don't perform an implicit conversion when calling it.
359356
template <class _Tp>
360357
struct __desugars_to<__equal_tag, equal_to<_Tp>, _Tp, _Tp> : true_type {};
361358

362-
#if _LIBCPP_STD_VER >= 14
363359
// In the transparent case, we do not enforce that
364360
template <class _Tp, class _Up>
365361
struct __desugars_to<__equal_tag, equal_to<void>, _Tp, _Up> : true_type {};
366-
#endif
367362

368363
#if _LIBCPP_STD_VER >= 14
369364
template <class _Tp = void>

libcxx/include/__functional/ranges_operations.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <__concepts/equality_comparable.h>
1414
#include <__concepts/totally_ordered.h>
1515
#include <__config>
16-
#include <__functional/operations.h>
1716
#include <__type_traits/integral_constant.h>
1817
#include <__type_traits/operation_traits.h>
1918
#include <__utility/forward.h>

libcxx/include/__type_traits/operation_traits.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222
struct __equal_tag {};
2323
struct __plus_tag {};
2424

25-
// In the general case, __desugars_to is false
26-
25+
// This class template is used to determine whether an operation "desugars"
26+
// (or boils down) to a given canonical operation.
27+
//
28+
// For example, `std::equal_to<>`, our internal `std::__equal_to` helper and
29+
// `ranges::equal_to` are all just fancy ways of representing a transparent
30+
// equality operation, so they all desugar to `__equal_tag`.
31+
//
32+
// This is useful to optimize some functions in cases where we know e.g. the
33+
// predicate being passed is actually going to call a builtin operator, or has
34+
// some specific semantics.
2735
template <class _CanonicalTag, class _Operation, class... _Args>
2836
struct __desugars_to : false_type {};
2937

libcxx/test/libcxx/algorithms/pstl.transform_reduce.string.pass.cpp

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)