<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># Copyright David Abrahams 2004. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
'''
&gt;&gt;&gt; from auto_ptr_ext import *
&gt;&gt;&gt; x = X(42)
&gt;&gt;&gt; x.value()
42
&gt;&gt;&gt; look(x), look(x)
(42, 42)

&gt;&gt;&gt; maybe_steal(x, 0)
42
&gt;&gt;&gt; look(x)
42

&gt;&gt;&gt; maybe_steal(x, 1)
42
&gt;&gt;&gt; broken_auto_ptr and -1 or look(x)
-1

&gt;&gt;&gt; x = X(69)
&gt;&gt;&gt; steal(x)
69
&gt;&gt;&gt; broken_auto_ptr and -1 or look(x)
-1

&gt;&gt;&gt; if not broken_auto_ptr:
...     try: x.value()
...     except TypeError: pass
...     else: print 'expected a TypeError exception'

&gt;&gt;&gt; x = make()
&gt;&gt;&gt; look(x)
77

&gt;&gt;&gt; z = callback(lambda z: z)
&gt;&gt;&gt; z.value()
77

&gt;&gt;&gt; extract(x).value()
77

#
# Test derived to base conversions
#

&gt;&gt;&gt; y = Y(42)
&gt;&gt;&gt; y.value()
42

&gt;&gt;&gt; try: maybe_steal(y, 0)
... except TypeError: pass
... else: print 'expected a TypeError exception'

&gt;&gt;&gt; y.value()
42

&gt;&gt;&gt; broken_auto_ptr and 42 or steal(y)
42

&gt;&gt;&gt; if not broken_auto_ptr:
...     try: y.value()
...     except TypeError: pass
...     else: print 'expected a TypeError exception'

&gt;&gt;&gt; print look.__doc__.splitlines()[1]
look( (X)arg1) -&gt; int :

&gt;&gt;&gt; print steal.__doc__.splitlines()[1]
steal( (X)arg1) -&gt; int :

&gt;&gt;&gt; print maybe_steal.__doc__.splitlines()[1]
maybe_steal( (X)arg1, (bool)arg2) -&gt; int :

&gt;&gt;&gt; print make.__doc__.splitlines()[1]
make() -&gt; X :

&gt;&gt;&gt; print callback.__doc__.splitlines()[1]
callback( (object)arg1) -&gt; X :

&gt;&gt;&gt; print extract.__doc__.splitlines()[1]
extract( (object)arg1) -&gt; X :

'''

def run(args = None):
    import sys
    import doctest

    if args is not None:
        sys.argv = args
    return doctest.testmod(sys.modules.get(__name__))
    
if __name__ == '__main__':
    print "running..."
    import sys
    status = run()[0]
    if (status == 0): print "Done."
    sys.exit(status)
</pre></body></html>