[C++-sig] bpl_utils explained

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Sun Jul 28 11:14:26 CEST 2002


--- David Abrahams <dave at boost-consulting.com> wrote:
> I'm appreciative of all the work you've been doing, so please don't take
> this the wrong way: I don't understand why the simple change of using a
> pointer or non-const reference as the first argument to one of your
> functions instead of a const reference is distasteful enough to warrant
> removing conversion from general sequences. That seems like a pretty
> radical change to make for the sake of the style of what is essentially an
> implementation detail.

The short answer:

The "simple change" did not seem generally applicable to me. People will
have code like:

struct user
{
  void foo(std::vector<double> const& v);
};


The longer answer:

Users will want to know:

How does overload resolution work if you have both a class_<T> and
register_container_from_python_sequence<T, some_policy>?

(where T is e.g. std::vector<U> or std::list<U>)

My previous posting gives /an/ answer that I thought a wider audience
can absorb and work with. Could you please modify the explanation under
"true" and "false" to reflect what you'd like to see? I could then
try the implementation.

Say you have

class_<std::vector<int> > ...
register_container_from_python_sequence<
  std::vector<int>,
  variable_size_container_registration_adaptor>();

class_<std::vector<double> > ...
register_container_from_python_sequence<
  std::vector<double>,
  variable_size_container_registration_adaptor>();

struct user
{
  void foo(std::vector<double> const& v);
};

class_<user> ...

Do you want a std::vector<int> to match the argument of foo()?
Another situation:

struct user
{
  void foo(std::vector<int> const& v);
  void foo(std::vector<double> const& v);
};

What should happen now?

Ralf

P.S.: I've remove my as_tuple() function because tuple() (or list() or
iter()) does the job anyway:

Python 2.2.1 (#1, Apr 10 2002, 12:12:48) [C] on osf1V5
Type "help", "copyright", "credits" or "license" for more information.
>>> from cctbx_boost.arraytbx import shared
>>> a=shared.double((1,2,3))
>>> a
<cctbx_boost.arraytbx.shared.double object at 0x1400f9cd8>
>>> list(a)
[1.0, 2.0, 3.0]
>>> tuple(a)
(1.0, 2.0, 3.0)
>>> i=iter(a)
>>> print i.next()
1.0
>>> print i.next()
2.0
>>> print i.next()
3.0
>>> print i.next()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
StopIteration


__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com




More information about the Cplusplus-sig mailing list