[C++-sig] Re: C arrays mk 2

Raoul Gough RaoulGough at yahoo.co.uk
Thu Oct 16 00:29:40 CEST 2003


David Abrahams <dave at boost-consulting.com> writes:

> Raoul Gough wrote:
>> David Abrahams <dave at boost-consulting.com> writes:
>>
>>>Raoul Gough wrote:
>> [snip]
>>
>>>>I suppose it depends how rich an interface he wants on the Python
>>>>side. The two methods you named are sufficient for a lot of cases
>>>>(almost everything, in fact), but if he wants slice support or
>>>>__setitem__, it might still pay off to use the container suite.
>>>
>>>Sure.  But his example just creates an iterator (the extremely hard
>>>way), and __len__ + __getitem__ already gets you an iterator and more.
>> That's right - it's neat how many Python expressions can work with
>> just those two methods (in fact, I think __len__ is not even necessary
>> for much of it, since IndexError works as well as StopIteration).
>> However, I think his code actually does enlist some extra
>> container_suite support via the iterator_pair container emulation,
>> which goes one or two steps further. The macros obscure it somewhat,
>> but I think it basically does this:
>> typedef indexing::iterator_pair<memberType *> IterPair;
>> class_<IterPair>("Name", init<...>)
>>   .def (indexing::container_suite<IterPair>());
>
> Ah, I didn't realize he was using the indexing suite.  Sorry!
> I think I have some arguments with the naming of iterator_pair, which
> is part of what threw me off.
> It really represents an "immutable sequence".  "iterator pair" is more
> like an implementation detail.

Welll, I don't know - it's not just *any* immutable sequence, because
it only works with iterators. I've actually wondered about the name
myself, but not for the reason you mentioned: it doesn't work with
every pair of iterator instances, because they have to specify a valid
range, like the requirements for std::distance ("last must be
reachable from first"). i.e. it's not the same as std::pair<iterator,
iterator>, because there are further requirements on the values used.

Also, I'm also not sure that it could really be called immutable,
since you can replace elements (just not insert or delete them).
Anyway, can you suggest an alternative name?

>
> As a side note, please use boost::detail::iterator_traits instead of
> std::iterator_traits, for portability reasons.

OK - will fix these.

>
> As another side note, endline layout
>
>    template<typename Iterator>
>    iterator_pair<Iterator>::iterator_pair (iterator_param begin
>                                            , iterator_param end)
>
> is banned in Boost.Python.  Should be, e.g.:
>
>    template<typename Iterator>
>    iterator_pair<Iterator>::iterator_pair (
>        iterator_param begin, iterator_param end)
>
> ;->

?What do you do when the parameter list itself gets too long for a
single line? I usually use the vertical layout as soon as I have to
split the line the first time.

>
> I'll stop picking nits with your excellent work now.

Well, a uniform coding style is always a good thing. I'm just
wondering how much effort this will involve, especially considering
that Emacs auto-indent won't co-operate with what you use (or have you
customized this somehow?). BTW, why do you dislike the vertical style?

-- 
Raoul Gough.
(setq dabbrev-case-fold-search nil)





More information about the Cplusplus-sig mailing list