public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tromey@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Rewrite gdb_mpz::operator==
Date: Tue, 25 Apr 2023 14:55:13 -0400	[thread overview]
Message-ID: <e6846627-e682-516b-d184-b263d9feea33@simark.ca> (raw)
In-Reply-To: <87edo9z1fv.fsf@tromey.com>

> diff --git a/gdb/gmp-utils.h b/gdb/gmp-utils.h
> index d05c11ecbe4..1bbdd9564fa 100644
> --- a/gdb/gmp-utils.h
> +++ b/gdb/gmp-utils.h
> @@ -323,31 +323,26 @@ struct gdb_mpz
>      return mpz_cmp_si (m_val, other) < 0;
>    }
>  
> -  bool operator== (int other) const
> -  {
> -    return mpz_cmp_si (m_val, other) == 0;
> -  }
> -
> -  bool operator== (long other) const
> -  {
> -    return mpz_cmp_si (m_val, other) == 0;
> -  }
> -
> -  bool operator== (unsigned long other) const
> -  {
> -    return mpz_cmp_ui (m_val, other) == 0;
> -  }
> -
> +  /* We want an operator== that can handle all integer types.  For
> +     types that are 'long' or narrower, we can use a GMP function and
> +     avoid boxing the RHS.  But, because overloading based on integer
> +     type is a pain in C++, we accept all such types here and check
> +     the size in the body.  */
>    template<typename T,
> -	   typename = gdb::Requires<
> -	     gdb::And<std::is_integral<T>,
> -		      std::integral_constant<bool,
> -					     (sizeof (T) > sizeof (long))>>
> -	     >
> -	   >
> -  bool operator== (T src)
> -  {
> -    return *this == gdb_mpz (src);
> +	   typename = gdb::Requires<std::is_integral<T>>>
The template expression would fit on a single line, if you'd prefer to
write it that way.

Otherwise, LGTM.  I think it's now relatively clear what the code tries
to achieve.

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon


      reply	other threads:[~2023-04-25 18:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-19 15:09 Tom Tromey
2023-04-19 16:23 ` Simon Marchi
2023-04-21 13:00   ` Tom Tromey
2023-04-21 13:13     ` Simon Marchi
2023-04-21 15:02       ` Tom Tromey
2023-04-24 16:31         ` Tom Tromey
2023-04-25 18:55           ` Simon Marchi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e6846627-e682-516b-d184-b263d9feea33@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).