public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ulrich Drepper <drepper@gmail.com>
To: libstdc++@gcc.gnu.org
Subject: tuple pretty printer
Date: Wed, 27 Jul 2022 18:40:12 +0200	[thread overview]
Message-ID: <CAOPLpQeEjCvdjsEpy-4BKPAA-gY5X=bD5niuQ1fXf=-44-2HxQ@mail.gmail.com> (raw)

The current tuple pretty printer shows for this variable

std::tuple<int,int,int> a{1,2,3};

the following output:

(gdb) p a
$1 = std::tuple containing = {[1] = 1, [2] = 2, [3] = 3}

I find this quite irritating because the indices don't match the
std::get template parameters.  In a large tuple or arrays of tuples
which are less readable than this simple example this becomes an even
larger problem.  How about the following simple patch which brings the
indices in line?

--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -611,9 +611,9 @@ class StdTuplePrinter:
             # the value "as is".
             fields = impl.type.fields ()
             if len (fields) < 1 or fields[0].name != "_M_head_impl":
-                return ('[%d]' % self.count, impl)
+                return ('[%d]' % (self.count - 1), impl)
             else:
-                return ('[%d]' % self.count, impl['_M_head_impl'])
+                return ('[%d]' % (self.count - 1), impl['_M_head_impl'])

     def __init__ (self, typename, val):
         self.typename = strip_versioned_namespace(typename)

             reply	other threads:[~2022-07-27 16:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-27 16:40 Ulrich Drepper [this message]
2022-08-04 11:03 ` Jonathan Wakely

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='CAOPLpQeEjCvdjsEpy-4BKPAA-gY5X=bD5niuQ1fXf=-44-2HxQ@mail.gmail.com' \
    --to=drepper@gmail.com \
    --cc=libstdc++@gcc.gnu.org \
    /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).