[C++-sig] Protected destructor compile error
David Abrahams
dave at boost-consulting.com
Fri Jun 23 05:12:50 CEST 2006
"Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com> writes:
> --- Roman Yakovenko <roman.yakovenko at gmail.com> wrote:
>
>> On 6/22/06, David Abrahams <dave at boost-consulting.com> wrote:
>> > Boost.Python assumes that a const reference argument means that
>> > the function can accept "rvalues", e.g. objects implicitly
>> > converted from other python types.
>>
>> I am sure I am missing something trivial.
>>
>> Why Boost.Python does such assumption?
Because that's the way it works in C++. The aim of Boost.Python is to
make the Python interface reflect the C++ interface. Probably
"assumes" was the wrong word. I should have said "is designed so."
>> In my opinion Boost.Python, in this case does not have to make any
>> assumption.
>>
>> If user want to enjoy from conversion he should register it, right?
>> He does this using:
>>
>> 1. implicitly_convertible
>> 2. register_ptr_to_python
>> 3. class_::bases
bases<...> has nothing to do with it; they don't enable rvalue
conversions. Nor does register_ptr_to_python. We're talking about
from-python conversions here.
>> If none of those has been used, Boost.Python can safely assume that
>> the class could not be built from other python types.
>
> Boost.Python also supports custom rvalue converters. See the FAQ for
> examples.
And there are built-in rvalue conversions, e.g., Python str to
std::string, Python float to C++ float, etc. You definitely don't
want the temporary string or float binding to a non-const reference.
> You'd need two different mechanisms for types that allow
> custom from_python conversions (involving the construction and
> destruction of temporaries) and those that don't. I am guessing
> David considered that extra effort not worthwhile or impractical.
Not really; I actually never considered treating types nonuniformly in
this way, and I don't think it would be tenable to do so based on
whether custom from_python conversions are allowed.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list