| Store | Cart

[C++-sig] extractors

From: Ralf W. Grosse-Kunstleve <r...@yahoo.com>
Mon, 15 Jul 2002 09:14:39 -0700 (PDT)
--- David Abrahams <david.abrahams at rcn.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?

Ideas:

a. I could simply limit the boost::array converters to lists and tuples. In our
environment this would be fully sufficient.

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.

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.

Ralf


__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com

Recent Messages in this Thread
David Abrahams Jul 15, 2002 07:52 am
Ralf W. Grosse-Kunstleve Jul 15, 2002 04:14 pm
Messages in this thread