[libcxx-commits] [libcxx] ca7926b - [libc++] Eliminate needless `add_lvalue_reference` from <algorithm> helpers. NFCI.
Arthur O'Dwyer via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Aug 22 08:43:50 PDT 2021
Author: Arthur O'Dwyer
Date: 2021-08-22T11:43:12-04:00
New Revision: ca7926bd79426fbd8b752d6513c77951db35109f
URL: https://github.com/llvm/llvm-project/commit/ca7926bd79426fbd8b752d6513c77951db35109f
DIFF: https://github.com/llvm/llvm-project/commit/ca7926bd79426fbd8b752d6513c77951db35109f.diff
LOG: [libc++] Eliminate needless `add_lvalue_reference` from <algorithm> helpers. NFCI.
When `_Compare` is a function parameter already (so it's not `void`
and it's not an abominable function type), `add_lvalue_reference_t<_Compare>`
is simply a synonym for `_Compare&`. We don't need to pull in `<type_traits>`
and instantiate a template trait to figure that out.
Differential Revision: https://reviews.llvm.org/D108400
Added:
Modified:
libcxx/include/__algorithm/comp_ref_type.h
libcxx/include/__algorithm/equal.h
libcxx/include/__algorithm/find_end.h
libcxx/include/__algorithm/is_permutation.h
libcxx/include/__algorithm/lower_bound.h
libcxx/include/__algorithm/partition.h
libcxx/include/__algorithm/remove_if.h
libcxx/include/__algorithm/search.h
libcxx/include/__algorithm/search_n.h
libcxx/include/__algorithm/sort.h
libcxx/include/__algorithm/stable_partition.h
libcxx/include/__algorithm/unique.h
libcxx/include/__algorithm/unique_copy.h
libcxx/include/__algorithm/upper_bound.h
Removed:
################################################################################
diff --git a/libcxx/include/__algorithm/comp_ref_type.h b/libcxx/include/__algorithm/comp_ref_type.h
index b3bca82c0953..bbb94506c273 100644
--- a/libcxx/include/__algorithm/comp_ref_type.h
+++ b/libcxx/include/__algorithm/comp_ref_type.h
@@ -10,7 +10,6 @@
#define _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
#include <__config>
-#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
@@ -73,7 +72,7 @@ struct __comp_ref_type {
// Pass the comparator by lvalue reference. Or in debug mode, using a
// debugging wrapper that stores a reference.
#ifndef _LIBCPP_DEBUG
- typedef typename add_lvalue_reference<_Comp>::type type;
+ typedef _Comp& type;
#else
typedef __debug_less<_Comp> type;
#endif
diff --git a/libcxx/include/__algorithm/equal.h b/libcxx/include/__algorithm/equal.h
index 2f47fc83a10d..3658d0a177cd 100644
--- a/libcxx/include/__algorithm/equal.h
+++ b/libcxx/include/__algorithm/equal.h
@@ -14,7 +14,6 @@
#include <__algorithm/comp.h>
#include <__iterator/distance.h>
#include <__iterator/iterator_traits.h>
-#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
@@ -61,14 +60,14 @@ __equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _Random
if (_VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2))
return false;
return _VSTD::equal<_RandomAccessIterator1, _RandomAccessIterator2,
- typename add_lvalue_reference<_BinaryPredicate>::type>(__first1, __last1, __first2, __pred);
+ _BinaryPredicate&>(__first1, __last1, __first2, __pred);
}
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
_BinaryPredicate __pred) {
- return _VSTD::__equal<typename add_lvalue_reference<_BinaryPredicate>::type>(
+ return _VSTD::__equal<_BinaryPredicate&>(
__first1, __last1, __first2, __last2, __pred, typename iterator_traits<_InputIterator1>::iterator_category(),
typename iterator_traits<_InputIterator2>::iterator_category());
}
diff --git a/libcxx/include/__algorithm/find_end.h b/libcxx/include/__algorithm/find_end.h
index f4277f003aa8..7dd20eba0611 100644
--- a/libcxx/include/__algorithm/find_end.h
+++ b/libcxx/include/__algorithm/find_end.h
@@ -13,7 +13,6 @@
#include <__config>
#include <__algorithm/comp.h>
#include <__iterator/iterator_traits.h>
-#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
@@ -134,7 +133,7 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredica
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1
find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2,
_BinaryPredicate __pred) {
- return _VSTD::__find_end<typename add_lvalue_reference<_BinaryPredicate>::type>(
+ return _VSTD::__find_end<_BinaryPredicate&>(
__first1, __last1, __first2, __last2, __pred, typename iterator_traits<_ForwardIterator1>::iterator_category(),
typename iterator_traits<_ForwardIterator2>::iterator_category());
}
diff --git a/libcxx/include/__algorithm/is_permutation.h b/libcxx/include/__algorithm/is_permutation.h
index e33a7157ddca..727308aceea6 100644
--- a/libcxx/include/__algorithm/is_permutation.h
+++ b/libcxx/include/__algorithm/is_permutation.h
@@ -15,7 +15,6 @@
#include <__iterator/distance.h>
#include <__iterator/iterator_traits.h>
#include <__iterator/next.h>
-#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
@@ -137,15 +136,14 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 bool __is_permutation(_RandomAccessIterator1 __fir
if (_VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2))
return false;
return _VSTD::is_permutation<_RandomAccessIterator1, _RandomAccessIterator2,
- typename add_lvalue_reference<_BinaryPredicate>::type>(__first1, __last1, __first2,
- __pred);
+ _BinaryPredicate&>(__first1, __last1, __first2, __pred);
}
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
_ForwardIterator2 __last2, _BinaryPredicate __pred) {
- return _VSTD::__is_permutation<typename add_lvalue_reference<_BinaryPredicate>::type>(
+ return _VSTD::__is_permutation<_BinaryPredicate&>(
__first1, __last1, __first2, __last2, __pred, typename iterator_traits<_ForwardIterator1>::iterator_category(),
typename iterator_traits<_ForwardIterator2>::iterator_category());
}
diff --git a/libcxx/include/__algorithm/lower_bound.h b/libcxx/include/__algorithm/lower_bound.h
index 1448c8963327..f353b6e57132 100644
--- a/libcxx/include/__algorithm/lower_bound.h
+++ b/libcxx/include/__algorithm/lower_bound.h
@@ -51,8 +51,7 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
- typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
- return _VSTD::__lower_bound<_Comp_ref>(__first, __last, __value_, __comp);
+ return _VSTD::__lower_bound<_Compare&>(__first, __last, __value_, __comp);
}
template <class _ForwardIterator, class _Tp>
diff --git a/libcxx/include/__algorithm/partition.h b/libcxx/include/__algorithm/partition.h
index c859eaca28a3..5e3872e80b25 100644
--- a/libcxx/include/__algorithm/partition.h
+++ b/libcxx/include/__algorithm/partition.h
@@ -13,7 +13,6 @@
#include <__iterator/iterator_traits.h>
#include <__utility/swap.h>
#include <utility> // pair
-#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
@@ -77,8 +76,8 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
{
- return _VSTD::__partition<typename add_lvalue_reference<_Predicate>::type>
- (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
+ return _VSTD::__partition<_Predicate&>(
+ __first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/include/__algorithm/remove_if.h b/libcxx/include/__algorithm/remove_if.h
index e506b4c67fba..893ec8d7b423 100644
--- a/libcxx/include/__algorithm/remove_if.h
+++ b/libcxx/include/__algorithm/remove_if.h
@@ -12,7 +12,6 @@
#include <__config>
#include <__algorithm/find_if.h>
#include <utility>
-#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
@@ -27,8 +26,7 @@ template <class _ForwardIterator, class _Predicate>
_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
{
- __first = _VSTD::find_if<_ForwardIterator, typename add_lvalue_reference<_Predicate>::type>
- (__first, __last, __pred);
+ __first = _VSTD::find_if<_ForwardIterator, _Predicate&>(__first, __last, __pred);
if (__first != __last)
{
_ForwardIterator __i = __first;
diff --git a/libcxx/include/__algorithm/search.h b/libcxx/include/__algorithm/search.h
index 008b8ebb04ad..2bedbb8afb67 100644
--- a/libcxx/include/__algorithm/search.h
+++ b/libcxx/include/__algorithm/search.h
@@ -13,7 +13,6 @@
#include <__algorithm/comp.h>
#include <__config>
#include <__iterator/iterator_traits.h>
-#include <type_traits>
#include <utility>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -101,7 +100,7 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredica
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1
search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2,
_BinaryPredicate __pred) {
- return _VSTD::__search<typename add_lvalue_reference<_BinaryPredicate>::type>(
+ return _VSTD::__search<_BinaryPredicate&>(
__first1, __last1, __first2, __last2, __pred,
typename iterator_traits<_ForwardIterator1>::iterator_category(),
typename iterator_traits<_ForwardIterator2>::iterator_category()).first;
diff --git a/libcxx/include/__algorithm/search_n.h b/libcxx/include/__algorithm/search_n.h
index 1584e8e613ce..ad560ad2889c 100644
--- a/libcxx/include/__algorithm/search_n.h
+++ b/libcxx/include/__algorithm/search_n.h
@@ -13,7 +13,7 @@
#include <__config>
#include <__algorithm/comp.h>
#include <__iterator/iterator_traits.h>
-#include <type_traits>
+#include <type_traits> // __convert_to_integral
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
@@ -97,7 +97,7 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator __search_n(_RandomAccessIter
template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator search_n(
_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_, _BinaryPredicate __pred) {
- return _VSTD::__search_n<typename add_lvalue_reference<_BinaryPredicate>::type>(
+ return _VSTD::__search_n<_BinaryPredicate&>(
__first, __last, _VSTD::__convert_to_integral(__count), __value_, __pred,
typename iterator_traits<_ForwardIterator>::iterator_category());
}
diff --git a/libcxx/include/__algorithm/sort.h b/libcxx/include/__algorithm/sort.h
index 39ec21302d20..ae99c8bde129 100644
--- a/libcxx/include/__algorithm/sort.h
+++ b/libcxx/include/__algorithm/sort.h
@@ -17,7 +17,6 @@
#include <__algorithm/unwrap_iter.h>
#include <__utility/swap.h>
#include <memory>
-#include <type_traits> // swap
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
@@ -131,9 +130,7 @@ __selection_sort(_BidirectionalIterator __first, _BidirectionalIterator __last,
_BidirectionalIterator __lm1 = __last;
for (--__lm1; __first != __lm1; ++__first)
{
- _BidirectionalIterator __i = _VSTD::min_element<_BidirectionalIterator,
- typename add_lvalue_reference<_Compare>::type>
- (__first, __last, __comp);
+ _BidirectionalIterator __i = _VSTD::min_element<_BidirectionalIterator, _Compare&>(__first, __last, __comp);
if (__i != __first)
swap(*__first, *__i);
}
diff --git a/libcxx/include/__algorithm/stable_partition.h b/libcxx/include/__algorithm/stable_partition.h
index 931335f44474..e0be0b6e5ef8 100644
--- a/libcxx/include/__algorithm/stable_partition.h
+++ b/libcxx/include/__algorithm/stable_partition.h
@@ -85,8 +85,7 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate
// recurse on [__first, __m), *__first know to be false
// F?????????????????
// f m l
- typedef typename add_lvalue_reference<_Predicate>::type _PredRef;
- _ForwardIterator __first_false = _VSTD::__stable_partition<_PredRef>(__first, __m, __pred, __len2, __p, __fit);
+ _ForwardIterator __first_false = _VSTD::__stable_partition<_Predicate&>(__first, __m, __pred, __len2, __p, __fit);
// TTTFFFFF??????????
// f ff m l
// recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true
@@ -101,7 +100,7 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate
}
// TTTFFFFFTTTF??????
// f ff m m1 l
- __second_false = _VSTD::__stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __fit);
+ __second_false = _VSTD::__stable_partition<_Predicate&>(__m1, __last, __pred, __len_half, __p, __fit);
__second_half_done:
// TTTFFFFFTTTTTFFFFF
// f ff m sf l
@@ -137,8 +136,7 @@ __stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate
__p = _VSTD::get_temporary_buffer<value_type>(__len);
__h.reset(__p.first);
}
- return _VSTD::__stable_partition<typename add_lvalue_reference<_Predicate>::type>
- (__first, __last, __pred, __len, __p, forward_iterator_tag());
+ return _VSTD::__stable_partition<_Predicate&>(__first, __last, __pred, __len, __p, forward_iterator_tag());
}
template <class _Predicate, class _BidirectionalIterator, class _Distance, class _Pair>
@@ -222,8 +220,7 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last
}
// F???TFFF?????????T
// f m1 m l
- typedef typename add_lvalue_reference<_Predicate>::type _PredRef;
- __first_false = _VSTD::__stable_partition<_PredRef>(__first, __m1, __pred, __len_half, __p, __bit);
+ __first_false = _VSTD::__stable_partition<_Predicate&>(__first, __m1, __pred, __len_half, __p, __bit);
__first_half_done:
// TTTFFFFF?????????T
// f ff m l
@@ -240,7 +237,7 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last
}
// TTTFFFFFTTTF?????T
// f ff m m1 l
- __second_false = _VSTD::__stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __bit);
+ __second_false = _VSTD::__stable_partition<_Predicate&>(__m1, __last, __pred, __len_half, __p, __bit);
__second_half_done:
// TTTFFFFFTTTTTFFFFF
// f ff m sf l
@@ -285,8 +282,7 @@ __stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last
__p = _VSTD::get_temporary_buffer<value_type>(__len);
__h.reset(__p.first);
}
- return _VSTD::__stable_partition<typename add_lvalue_reference<_Predicate>::type>
- (__first, __last, __pred, __len, __p, bidirectional_iterator_tag());
+ return _VSTD::__stable_partition<_Predicate&>(__first, __last, __pred, __len, __p, bidirectional_iterator_tag());
}
template <class _ForwardIterator, class _Predicate>
@@ -294,8 +290,7 @@ inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator
stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
{
- return _VSTD::__stable_partition<typename add_lvalue_reference<_Predicate>::type>
- (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
+ return _VSTD::__stable_partition<_Predicate&>(__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/include/__algorithm/unique.h b/libcxx/include/__algorithm/unique.h
index fb6251a39a82..e03c2669a2d5 100644
--- a/libcxx/include/__algorithm/unique.h
+++ b/libcxx/include/__algorithm/unique.h
@@ -14,7 +14,6 @@
#include <__algorithm/adjacent_find.h>
#include <__iterator/iterator_traits.h>
#include <__utility/move.h>
-#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
@@ -31,8 +30,7 @@ template <class _ForwardIterator, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred)
{
- __first = _VSTD::adjacent_find<_ForwardIterator, typename add_lvalue_reference<_BinaryPredicate>::type>
- (__first, __last, __pred);
+ __first = _VSTD::adjacent_find<_ForwardIterator, _BinaryPredicate&>(__first, __last, __pred);
if (__first != __last)
{
// ... a a ? ...
diff --git a/libcxx/include/__algorithm/unique_copy.h b/libcxx/include/__algorithm/unique_copy.h
index 974a7c4df2d4..027b3244557e 100644
--- a/libcxx/include/__algorithm/unique_copy.h
+++ b/libcxx/include/__algorithm/unique_copy.h
@@ -13,7 +13,6 @@
#include <__algorithm/comp.h>
#include <__iterator/iterator_traits.h>
#include <utility>
-#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
@@ -91,8 +90,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred)
{
- return _VSTD::__unique_copy<typename add_lvalue_reference<_BinaryPredicate>::type>
- (__first, __last, __result, __pred,
+ return _VSTD::__unique_copy<_BinaryPredicate&>(__first, __last, __result, __pred,
typename iterator_traits<_InputIterator>::iterator_category(),
typename iterator_traits<_OutputIterator>::iterator_category());
}
diff --git a/libcxx/include/__algorithm/upper_bound.h b/libcxx/include/__algorithm/upper_bound.h
index 7be607f82538..b580190efa64 100644
--- a/libcxx/include/__algorithm/upper_bound.h
+++ b/libcxx/include/__algorithm/upper_bound.h
@@ -51,8 +51,7 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
- typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
- return _VSTD::__upper_bound<_Comp_ref>(__first, __last, __value_, __comp);
+ return _VSTD::__upper_bound<_Compare&>(__first, __last, __value_, __comp);
}
template <class _ForwardIterator, class _Tp>
More information about the libcxx-commits
mailing list