[C++-sig] Re: return value policy for returning same python object...
David Abrahams
dave at boost-consulting.com
Mon Jun 16 02:05:49 CEST 2003
Nikolay Mladenov <nickm at sitius.com> writes:
> Sorry...
>
> David Abrahams wrote:
>>
>> Nikolay Mladenov <nickm at sitius.com> writes:
>>
>> > What do you think about the following?
>> >
>> > namespace boost { namespace python
>> > {
>> > struct return_self : default_call_policies
>> > {
>> > static PyObject* postcall(PyObject *args, PyObject* ){
>> > return incref(PyTuple_GetItem(args,0));
>> > }
>> > struct result_converter
>> > {
>> > template <class T> struct apply{
>> > struct type{
>> > static bool convertible() {return true;}
>> > PyObject *operator()(T) const {return 0;}
>> ^
>> I'd like to see ---------------------------^
>>
>> typename add_reference<typenameadd_const<T>::type>::type
>>
>> right here.
>
> What is the reason for that? Shouldn't the parameter passing be
> optimised away anyway?
Not if the copy ctor has observable side-effects. There's no allowed
value-arg-optimization, so compilers will often not optimize away
copies in cases like this. Try it yourself with a
std::vector<double>.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list