Re: [C++-sig] extractors
by David Abrahams other posts by this author
Jul 15 2002 8:49PM messages near this date
Re: [C++-sig] Re: boost build problem
|
[C++-sig] to_python_converter and object
%2B%2B-SIG ----- Original Message -----
From: "Ralf W. Grosse-Kunstleve" <rwgk@[...].com>
To: <c++-sig@[...].org>
Sent: Monday, July 15, 2002 12:14 PM
Subject: Re: [C++-sig] extractors
> --- David Abrahams <david.abrahams@[...].com> wrote:
> > d. Ultimately, that means that if the overload succeds, but the
> > iterable contains the wrong kind of elements, the selected function
itself
> > will appear (from the Python side) to throw an exception immediately.
That
> > seems acceptable to me.
>
> The tests that go with my prototype implementation of the sequence ->
container
> converter include a test for these overloads:
>
> int boost_array_3(boost::array<double, 3> const& a);
> int boost_array_4(boost::array<double, 4> const& a);
>
> .def("boost_array", boost_array_3)
> .def("boost_array", boost_array_4)
>
> For this to work as expected the convertible() test has to know the
number of
> elements in the sequence. Is this possible if the input sequence can only
be
> traversed once?
If it exposes a __len__ method, I think the answer is yes ;-)
> Ideas:
>
> a. I could simply limit the boost::array converters to lists and tuples.
In our
> environment this would be fully sufficient.
I think it would be fine to limit them to iterables with __len__ methods.
List and tuple both fall into this category.
> b. Or, if the input Python object is a list or tuple I check the length.
> Otherwise convertible() returns true and construct() throws an exception
if the
> sequence length is not compatible.
Whether or not this is acceptable/appropriate really depends on the users'
needs. Since you guys are the users, I guess I have no comment.
> c. Extending the idea: if the input Python object is a list or tuple I
check
> both the length and the convertibility of each element. For any other
sequence
> convertible() returns true and construct() throws an exception if there
is a
> problem.
I think the real, deep answers to this lie somewhere in PEP 246:
http://www.python.org/peps/pep-0246.html
-Dave
Thread:
David Abrahams
Ralf W. Grosse-Kunstleve
David Abrahams
|