[C++-sig] tuple, list, dict, et. al

David Abrahams david.abrahams at rcn.com
Tue Jun 25 23:52:26 CEST 2002


The answers below are mine, but I'm interested in feedback about them.

----

Question:
    What should the following do, where o is a python::object?

        tuple(o)

Answer:

    I believe (strongly) that it should do something exactly
    corresponding to what does in Python:

    >>> help(tuple)
    Help on class tuple in module __builtin__:

    class tuple(object)
     |  tuple() -> an empty tuple
     |  tuple(sequence) -> tuple initialized from sequence's items
     |
     |  If the argument is a tuple, the return value is the same object.

Question:

    How do I specify that a wrapped function accepts a tuple argument?

Answer:

    Put a boost::tuple in the function signature

Question:

    What should that mean in terms of overload resolution?

Answer 1:

    The function only matches if the actual argument is a Python
    tuple or a subclass of tuple

Answer 2:

    The function matches if the actual argument is any Python sequence;
    tuple(arg) will be applied to retrieve the tuple object used inside
    the wrapped function

Which of the above answers is better? So far liberal conversion during
function matching (e.g. Python Float -> C++ int) has caused problems
for at least one person. On the other hand, in the long run that
problem should be resolved and overloads should be resolved more-smartly.

Opinions?

-Dave

+---------------------------------------------------------------+
                  David Abrahams
      C++ Booster (http://www.boost.org)               O__  ==
      Pythonista (http://www.python.org)              c/ /'_ ==
  resume: http://users.rcn.com/abrahams/resume.html  (*) \(*) ==
          email: david.abrahams at rcn.com
+---------------------------------------------------------------+






More information about the Cplusplus-sig mailing list