Patchwork [v3] libstdc++/48362 - pretty printer for std::tuple<> with no elements

login
register
mail settings
Submitter Jonathan Wakely
Date Dec. 22, 2011, 12:44 p.m.
Message ID <CAH6eHdQpCucX6x6ZpHBH3ihk35NjvDw5umMNR0c-GAEHn4mzzQ@mail.gmail.com>
Download mbox | patch
Permalink /patch/132841/
State New
Headers show

Comments

Jonathan Wakely - Dec. 22, 2011, 12:44 p.m.
PR libstdc++/48362
        * python/libstdcxx/v6/printers.py (StdTuplePrinter): Handle empty
        tuples.

There might be a neater way to fix this, but this does the job.

Committed to trunk.

Patch

Index: python/libstdcxx/v6/printers.py
===================================================================
--- python/libstdcxx/v6/printers.py	(revision 182619)
+++ python/libstdcxx/v6/printers.py	(revision 182620)
@@ -251,11 +251,11 @@  class StdTuplePrinter:
             # Set the base class as the initial head of the
             # tuple.
             nodes = self.head.type.fields ()
-            if len (nodes) != 1:
+            if len (nodes) == 1:
+                # Set the actual head to the first pair.
+                self.head  = self.head.cast (nodes[0].type)
+            elif len (nodes) != 0:
                 raise ValueError, "Top of tuple tree does not consist of a single node."
-
-            # Set the actual head to the first pair.
-            self.head  = self.head.cast (nodes[0].type)
             self.count = 0
 
         def __iter__ (self):
@@ -297,6 +297,8 @@  class StdTuplePrinter:
         return self._iterator (self.val)
 
     def to_string (self):
+        if len (self.val.type.fields ()) == 0:
+            return 'empty %s' % (self.typename)
         return '%s containing' % (self.typename)
 
 class StdStackOrQueuePrinter: