public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* tuple pretty printer
@ 2022-07-27 16:40 Ulrich Drepper
  2022-08-04 11:03 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Ulrich Drepper @ 2022-07-27 16:40 UTC (permalink / raw)
  To: libstdc++

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)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: tuple pretty printer
  2022-07-27 16:40 tuple pretty printer Ulrich Drepper
@ 2022-08-04 11:03 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2022-08-04 11:03 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: libstdc++, gcc Patches

CC gcc-patches

On Wed, 27 Jul 2022 at 17:40, Ulrich Drepper via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> 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?

I think this makes sense, want to push it?


>
> --- 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)
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-08-04 11:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-27 16:40 tuple pretty printer Ulrich Drepper
2022-08-04 11:03 ` Jonathan Wakely

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).