[4/4] libstdc++: Simplify std::variant comparison operators

Message ID 20240410085039.267589-4-jwakely@redhat.com
State New
Headers
Series [1/4] libstdc++: Heterogeneous std::pair comparisons [PR113386] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Testing passed

Commit Message

Jonathan Wakely April 10, 2024, 8:45 a.m. UTC
  Tested x86_64-linux.

This is just a minor clean-up and could wait for stage 1.

-- >8 --

libstdc++-v3/ChangeLog:

	* include/std/variant (_VARIANT_RELATION_FUNCTION_TEMPLATE):
	Simplify.
---
 libstdc++-v3/include/std/variant | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)
  

Comments

Jonathan Wakely May 7, 2024, 1:45 p.m. UTC | #1
On Wed, 10 Apr 2024 at 09:51, Jonathan Wakely wrote:
>
> Tested x86_64-linux.
>
> This is just a minor clean-up and could wait for stage 1.

Pushed now.

>
> -- >8 --
>
> libstdc++-v3/ChangeLog:
>
>         * include/std/variant (_VARIANT_RELATION_FUNCTION_TEMPLATE):
>         Simplify.
> ---
>  libstdc++-v3/include/std/variant | 20 +++++++++-----------
>  1 file changed, 9 insertions(+), 11 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
> index 5ba6d9d42e3..2be0f0c1db7 100644
> --- a/libstdc++-v3/include/std/variant
> +++ b/libstdc++-v3/include/std/variant
> @@ -1245,7 +1245,7 @@ namespace __variant
>  # define _VARIANT_RELATION_FUNCTION_CONSTRAINTS(TYPES, OP)
>  #endif
>
> -#define _VARIANT_RELATION_FUNCTION_TEMPLATE(__OP, __NAME) \
> +#define _VARIANT_RELATION_FUNCTION_TEMPLATE(__OP) \
>    template<typename... _Types> \
>      _VARIANT_RELATION_FUNCTION_CONSTRAINTS(_Types, __OP) \
>      constexpr bool \
> @@ -1262,22 +1262,20 @@ namespace __variant
>                 { \
>                   auto& __this_mem = std::get<__rhs_index>(__lhs);      \
>                    __ret = __this_mem __OP __rhs_mem; \
> +                 return; \
>                  } \
> -             else \
> -               __ret = (__lhs.index() + 1) __OP (__rhs_index + 1); \
>              } \
> -          else \
> -            __ret = (__lhs.index() + 1) __OP (__rhs_index + 1); \
> +         __ret = (__lhs.index() + 1) __OP (__rhs_index + 1); \
>         }, __rhs); \
>        return __ret; \
>      }
>
> -  _VARIANT_RELATION_FUNCTION_TEMPLATE(<, less)
> -  _VARIANT_RELATION_FUNCTION_TEMPLATE(<=, less_equal)
> -  _VARIANT_RELATION_FUNCTION_TEMPLATE(==, equal)
> -  _VARIANT_RELATION_FUNCTION_TEMPLATE(!=, not_equal)
> -  _VARIANT_RELATION_FUNCTION_TEMPLATE(>=, greater_equal)
> -  _VARIANT_RELATION_FUNCTION_TEMPLATE(>, greater)
> +  _VARIANT_RELATION_FUNCTION_TEMPLATE(<)
> +  _VARIANT_RELATION_FUNCTION_TEMPLATE(<=)
> +  _VARIANT_RELATION_FUNCTION_TEMPLATE(==)
> +  _VARIANT_RELATION_FUNCTION_TEMPLATE(!=)
> +  _VARIANT_RELATION_FUNCTION_TEMPLATE(>=)
> +  _VARIANT_RELATION_FUNCTION_TEMPLATE(>)
>
>  #undef _VARIANT_RELATION_FUNCTION_TEMPLATE
>
> --
> 2.44.0
>
  

Patch

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 5ba6d9d42e3..2be0f0c1db7 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -1245,7 +1245,7 @@  namespace __variant
 # define _VARIANT_RELATION_FUNCTION_CONSTRAINTS(TYPES, OP)
 #endif
 
-#define _VARIANT_RELATION_FUNCTION_TEMPLATE(__OP, __NAME) \
+#define _VARIANT_RELATION_FUNCTION_TEMPLATE(__OP) \
   template<typename... _Types> \
     _VARIANT_RELATION_FUNCTION_CONSTRAINTS(_Types, __OP) \
     constexpr bool \
@@ -1262,22 +1262,20 @@  namespace __variant
 	        { \
 		  auto& __this_mem = std::get<__rhs_index>(__lhs);	\
                   __ret = __this_mem __OP __rhs_mem; \
+		  return; \
                 } \
-	      else \
-		__ret = (__lhs.index() + 1) __OP (__rhs_index + 1); \
             } \
-          else \
-            __ret = (__lhs.index() + 1) __OP (__rhs_index + 1); \
+	  __ret = (__lhs.index() + 1) __OP (__rhs_index + 1); \
 	}, __rhs); \
       return __ret; \
     }
 
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(<, less)
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(<=, less_equal)
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(==, equal)
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(!=, not_equal)
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(>=, greater_equal)
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(>, greater)
+  _VARIANT_RELATION_FUNCTION_TEMPLATE(<)
+  _VARIANT_RELATION_FUNCTION_TEMPLATE(<=)
+  _VARIANT_RELATION_FUNCTION_TEMPLATE(==)
+  _VARIANT_RELATION_FUNCTION_TEMPLATE(!=)
+  _VARIANT_RELATION_FUNCTION_TEMPLATE(>=)
+  _VARIANT_RELATION_FUNCTION_TEMPLATE(>)
 
 #undef _VARIANT_RELATION_FUNCTION_TEMPLATE