Compat: Missing things from libstdc++-v3/python/libstdcxx/v6/printers.py

Paul Smith paul@mad-scientist.net
Mon Dec 19 15:31:00 GMT 2016


On Mon, 2016-12-19 at 10:27 +0000, Jonathan Wakely wrote:
> You want a Python Iterable for a container. That already exists for
> std::map, std::set etc. and is used to implement the pretty printer
> for those types:
> 
> class RbtreeIterator(Iterator):
>     """
>     Turn an RB-tree-based container (std::map, std::set etc.) into
>     a Python iterable object.
>     """
> 
> There's no reason it can't be done for other containers, but somebody
> needs to do the work. Somebody who wants this. Hint hint ;-)

:)

It looks like there are already iterators for the other STL types as
well, but they're private to the printer class and specific for printing
as opposed to being a general-case iterator:

  class StdListPrinter:
      "Print a std::list"

      class _iterator(Iterator):
        ...

We can convert these into general-purpose iterators with a GDB printer
wrapper around them, as is done with the RbtreeIterator.

I think it would be better to have the iterator yield an item with the
correct type directly, and also to create an alias for each STL
container rather than having the user "know" that a std::set should use
the same iterator as std::map because they're both implemented with RB
trees.

E.g., have a StdListIterator, StdMapIterator, StdSetIterator, etc.

It's likely that we'll need to use these "in anger" to understand
exactly how they should work.



More information about the Gcc-help mailing list