[C++-sig] Re: return_self_policy
David Abrahams
dave at boost-consulting.com
Tue Jun 24 17:20:59 CEST 2003
Nikolay Mladenov <nickm at sitius.com> writes:
> David Abrahams wrote:
>>
>> Nikolay Mladenov ?nickm at sitius.com? writes:
>>
>> ? Posting return_self policy implementation
>> ?
>> ? Nikolay'''
>>
>> Nikolay,
>>
>> This is wonderful! Now, I hate to do this, but I just realized that
>> this should really be generalized to something which takes an
>> argument number as its parameter and returns that argument:
>
> I have already thought about it (I expected it from you ;-) )
> and it is already there in some form:
> the definition of return_self_policy is
>
> template<class Base>
> struct return_self_policy :
> detail::return_arg<0, Base> {}
>
Oh, wonderful! Very shrewd of you to anticipate me.
>>
>> return_identity?0? // error
>> return_identity??, return_identity?1? // same as return_self_policy
>> return_identity?2? // return the 2nd argument
>> return_identity?3? // return the 3rd argument
>> ...
>>
>> etc.
>
> So return_arg is as your return_identity, although return_arg<0> is not
> an error but return_self.
Well, y'see, by convention in call policies, zero is used to refer to
the return value and 1 refers to the first argument. See
with_custodian_and_ward.
>> Don't you think that makes more sense? Would you mind making this
>> modification?
>
> I agree that it makes more sense, but I am not sure how much the
> "more" is.
:-)
> Generally I don't mind.
>
>>
>> Thoughts, objections, screaming...?
>
> My question is: why start counting from 1? This will make the code more
> complicated and difficult to read.
Consistency. It's a convention in CallPolicies.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list