[C++-sig] Re: (return_self_policy / return_arg): Keywors

Nikolay Mladenov nickm at sitius.com
Tue Jul 1 00:23:24 CEST 2003


I've attached test files.

> OK, I don't understand this.  Isn't the 2nd constructor redundant?
Yes it is but, having it makes certain calls more efficient (it's
cheating, in a way ), 
see the commented section in the py-file, may be def with args can be
made so it is really redundant.
> Why are you using no_init?  
For the same reason, not that it makes sence for my first example, but
in general, 
I want my most offsen called overload to be first in the list - so
defined last.

> Doesn't this stuff work for regular
> functions and member functions, too?
Yes it works, see the test.

> ...and shouldn't we get rid of the need to write the outer
> "args(...)"?
It is not necessary to have it, you can write 
	(arg("a") = (int)0, arg("b") = (double)0, arg("n") = std::string()))
instead of
	args(arg("a") = (int)0, arg("b") = (double)0, arg("n") =
std::string()))
but you'll probably want
	args("a","b","c", arg("n") = std::string()))
instead of
	(arg("a"), arg("b"), arg("c"), arg("n") = std::string()))

> 
> I suggest you write the documentation which would explain all this,
Sure, but I think I'll wait a bit to see all of your comments:)

> but posting informally is fine if you try to ensure that I don't have
> to ask you lots more questions in order to understand it ;-)

I hope this all makes sense to you.

Regards

> 
> >> Nit: the coding style should be made consistent with the rest of the
> >> library.  These don't really fit:
> >>
> >> >                     std::size_t j = nargs, k = nargs, size=PyTuple_GET_SIZE(f->m_arg_names.ptr());
> >>
> >> >                         }else ++k;
> >>
> >
> > I will look into this. If you mean that some new line are missing,
> > consider it fixed.
> 
> Also that you used commas between variable declarations, K&R braces
> within functions, no spaces around '?', '<', '>', ...
> 
> --
> Dave Abrahams
> Boost Consulting
> www.boost-consulting.com
-------------- next part --------------
'''
>>> from keywords import *
>>> f = Foo()
>>> b = Bar()
>>> f.a(), f.b(), f.n()
(0, 0.0, '')
>>> b.a(), b.b(), b.n()
(0, 0.0, '')
>>> f = Foo(1)
>>> b = Bar(1)
>>> f.a(), f.b(), f.n()
(1, 0.0, '')
>>> b.a(), b.b(), b.n()
(1, 0.0, '')
>>> f = Foo(1,1.0)
>>> b = Bar(1,1.0)
>>> f.a(), f.b(), f.n()
(1, 1.0, '')
>>> b.a(), b.b(), b.n()
(1, 1.0, '')
>>> f = Foo(1,1.0,"1")
>>> b = Bar(1,1.0,"1")
>>> f.a(), f.b(), f.n()
(1, 1.0, '1')
>>> b.a(), b.b(), b.n()
(1, 1.0, '1')
>>> f = Foo(a=1)
>>> b = Bar(a=1)
>>> f.a(), f.b(), f.n()
(1, 0.0, '')
>>> b.a(), b.b(), b.n()
(1, 0.0, '')
>>> f = Foo(b=1)
>>> b = Bar(b=1)
>>> f.a(), f.b(), f.n()
(0, 1.0, '')
>>> b.a(), b.b(), b.n()
(0, 1.0, '')
>>> f = Foo(n="1")
>>> b = Bar(n="1")
>>> f.a(), f.b(), f.n()
(0, 0.0, '1')
>>> b.a(), b.b(), b.n()
(0, 0.0, '1')
>>> f = Foo(1,n="1")
>>> b = Bar(1,n="1")
>>> f.a(), f.b(), f.n()
(1, 0.0, '1')
>>> b.a(), b.b(), b.n()
(1, 0.0, '1')
>>> f.set()
>>> b.set()
>>> f.a(), f.b(), f.n()
(0, 0.0, '')
>>> b.a(), b.b(), b.n()
(0, 0.0, '')
>>> f.set(1)
>>> b.set(1)
>>> f.a(), f.b(), f.n()
(1, 0.0, '')
>>> b.a(), b.b(), b.n()
(1, 0.0, '')
>>> f.set(1,1.0)
>>> b.set(1,1.0)
>>> f.a(), f.b(), f.n()
(1, 1.0, '')
>>> b.a(), b.b(), b.n()
(1, 1.0, '')
>>> f.set(1,1.0,"1")
>>> b.set(1,1.0,"1")
>>> f.a(), f.b(), f.n()
(1, 1.0, '1')
>>> b.a(), b.b(), b.n()
(1, 1.0, '1')
>>> f.set(a=1)
>>> b.set(a=1)
>>> f.a(), f.b(), f.n()
(1, 0.0, '')
>>> b.a(), b.b(), b.n()
(1, 0.0, '')
>>> f.set(b=1)
>>> b.set(b=1)
>>> f.a(), f.b(), f.n()
(0, 1.0, '')
>>> b.a(), b.b(), b.n()
(0, 1.0, '')
>>> f.set(n="1")
>>> b.set(n="1")
>>> f.a(), f.b(), f.n()
(0, 0.0, '1')
>>> b.a(), b.b(), b.n()
(0, 0.0, '1')
>>> f.set(1,n="1")
>>> b.set(1,n="1")
>>> f.a(), f.b(), f.n()
(1, 0.0, '1')
>>> b.a(), b.b(), b.n()
(1, 0.0, '1')
'''


#############################
# Sample from my computer
#############################
#>>> from time import time
#>>> def callNtimes(f, n=100000):
#...  t = time()
#...  for i in range(0,n):
#...   f()
#...  return time()-t
#...
#>>> callNtimes(f.set)
#1.1100000143051147
#>>> callNtimes(b.set)
#2.4220000505447388
#>>> callNtimes(lambda: f.set(1))
#1.968000054359436
#>>> callNtimes(lambda: b.set(1))
#2.8289999961853027
#>>> callNtimes(lambda: f.set(1,.1))
#2.3279999494552612
#>>> callNtimes(lambda: b.set(1,.1))
#2.843999981880188
#>>> callNtimes(lambda: f.set(1,.1,'1'))
#2.656000018119812
#>>> callNtimes(lambda: b.set(1,.1,'1'))
#2.656999945640564

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
    sys.exit(run()[0])

-------------- next part --------------
A non-text attachment was scrubbed...
Name: keywords.cpp
Type: application/x-unknown-content-type-cppfile
Size: 2999 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030630/95e9e578/attachment.bin>


More information about the Cplusplus-sig mailing list