[gcc/devel/c++-coroutines] libstdc++: Remove redundant bool casts in ranges algorithms

Iain D Sandoe iains@gcc.gnu.org
Wed Feb 19 20:55:00 GMT 2020


https://gcc.gnu.org/g:a45fb21a10f486f6596b648e2c64bd1c7d808f18

commit a45fb21a10f486f6596b648e2c64bd1c7d808f18
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Feb 19 10:40:24 2020 +0000

    libstdc++: Remove redundant bool casts in ranges algorithms
    
    Some of these casts were added by me the other day, but some were
    already present. I think they are all redundant following the
    introduction of the boolean-testable concept in P1964R2.
    
    	* include/bits/ranges_algo.h (__find_fn, __find_first_of_fn)
    	(__adjacent_find_fn, __remove_if_fn, __remove_copy_if_fn)
    	(__unique_fn, __unique_copy_fn): Remove redundant conversions to bool.

Diff:
---
 libstdc++-v3/ChangeLog                  |  6 ++++++
 libstdc++-v3/include/bits/ranges_algo.h | 36 ++++++++++++++++-----------------
 2 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index b60f5c3..a8fcd7c 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,9 @@
+2020-02-19  Jonathan Wakely  <jwakely@redhat.com>
+
+	* include/bits/ranges_algo.h (__find_fn, __find_first_of_fn)
+	(__adjacent_find_fn, __remove_if_fn, __remove_copy_if_fn)
+	(__unique_fn, __unique_copy_fn): Remove redundant conversions to bool.
+
 2020-02-18  Patrick Palka  <ppalka@redhat.com>
 
 	P1983R0 Wording for GB301, US296, US292, US291, and US283
diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h
index 31b1bf0..a69181e 100644
--- a/libstdc++-v3/include/bits/ranges_algo.h
+++ b/libstdc++-v3/include/bits/ranges_algo.h
@@ -244,7 +244,7 @@ namespace ranges
 		 const _Tp& __value, _Proj __proj = {}) const
       {
 	while (__first != __last
-	    && !(bool)(std::__invoke(__proj, *__first) == __value))
+	    && !(std::__invoke(__proj, *__first) == __value))
 	  ++__first;
 	return __first;
       }
@@ -333,9 +333,9 @@ namespace ranges
       {
 	for (; __first1 != __last1; ++__first1)
 	  for (auto __iter = __first2; __iter != __last2; ++__iter)
-	    if ((bool)std::__invoke(__pred,
-				    std::__invoke(__proj1, *__first1),
-				    std::__invoke(__proj2, *__iter)))
+	    if (std::__invoke(__pred,
+			      std::__invoke(__proj1, *__first1),
+			      std::__invoke(__proj2, *__iter)))
 	      return __first1;
 	return __first1;
       }
@@ -730,9 +730,9 @@ namespace ranges
 	auto __next = __first;
 	for (; ++__next != __last; __first = __next)
 	  {
-	    if ((bool)std::__invoke(__pred,
-				    std::__invoke(__proj, *__first),
-				    std::__invoke(__proj, *__next)))
+	    if (std::__invoke(__pred,
+			      std::__invoke(__proj, *__first),
+			      std::__invoke(__proj, *__next)))
 	      return __first;
 	  }
 	return __next;
@@ -1219,7 +1219,7 @@ namespace ranges
 	auto __result = __first;
 	++__first;
 	for (; __first != __last; ++__first)
-	  if (!(bool)std::__invoke(__pred, std::__invoke(__proj, *__first)))
+	  if (!std::__invoke(__pred, std::__invoke(__proj, *__first)))
 	    {
 	      *__result = std::move(*__first);
 	      ++__result;
@@ -1289,7 +1289,7 @@ namespace ranges
 		 _Pred __pred, _Proj __proj = {}) const
       {
 	for (; __first != __last; ++__first)
-	  if (!(bool)std::__invoke(__pred, std::__invoke(__proj, *__first)))
+	  if (!std::__invoke(__pred, std::__invoke(__proj, *__first)))
 	    {
 	      *__result = *__first;
 	      ++__result;
@@ -1372,9 +1372,9 @@ namespace ranges
 	auto __dest = __first;
 	++__first;
 	while (++__first != __last)
-	  if (!(bool)std::__invoke(__comp,
-				   std::__invoke(__proj, *__dest),
-				   std::__invoke(__proj, *__first)))
+	  if (!std::__invoke(__comp,
+			     std::__invoke(__proj, *__dest),
+			     std::__invoke(__proj, *__first)))
 	    *++__dest = std::move(*__first);
 	return {++__dest, __first};
       }
@@ -1420,9 +1420,9 @@ namespace ranges
 	    auto __next = __first;
 	    *__result = *__next;
 	    while (++__next != __last)
-	      if (!(bool)std::__invoke(__comp,
-				       std::__invoke(__proj, *__first),
-				       std::__invoke(__proj, *__next)))
+	      if (!std::__invoke(__comp,
+				 std::__invoke(__proj, *__first),
+				 std::__invoke(__proj, *__next)))
 		{
 		  __first = __next;
 		  *++__result = *__first;
@@ -1434,9 +1434,9 @@ namespace ranges
 	  {
 	    *__result = *__first;
 	    while (++__first != __last)
-	      if (!(bool)std::__invoke(__comp,
-				       std::__invoke(__proj, *__result),
-				       std::__invoke(__proj, *__first)))
+	      if (!std::__invoke(__comp,
+				 std::__invoke(__proj, *__result),
+				 std::__invoke(__proj, *__first)))
 		  *++__result = *__first;
 	    return {std::move(__first), std::move(++__result)};
 	  }



More information about the Libstdc++-cvs mailing list