Skip to content

Instantly share code, notes, and snippets.

@tenpercent
Last active November 17, 2015 17:28
Show Gist options
  • Save tenpercent/cfba593e35406256fff3 to your computer and use it in GitHub Desktop.
Save tenpercent/cfba593e35406256fff3 to your computer and use it in GitHub Desktop.
pretty-printer for std::unique_ptr enabled for recursive printing
class MUniquePointerPrinter:
""" Print a unique_ptr with pointed-to-value
credits: https://gcc.gnu.org/ml/libstdc++/2013-04/msg00098.html
"""
def __init__ (self, typename, val):
self.val = val
def to_string (self):
v = self.val['_M_t']['_M_head_impl']
return ('std::unique_ptr<%s> containing %s' % (str(v.type.target()),
str(v)))
def children (self):
l_address = self.val['_M_t']['_M_head_impl']
l_value = 'NULL' if l_address == 0 else l_address.dereference ()
return iter([('<managed value>', l_value)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment