[C++-sig] Re: New slice implementation
David Abrahams
dave at boost-consulting.com
Thu Jan 8 15:42:30 CET 2004
Thanks for your submission, Jonathan! I can say right off that it
looks like good code but it's missing tests and docs and I can't
accept it without those.
I haven't been ignoring it, but wanted to wait to wait for this little
debate come to some conclusions...
Raoul Gough <RaoulGough at yahoo.co.uk> writes:
> Jonathan Brandmeyer <jbrandmeyer at earthlink.net> writes:
>
>> On Tue, 2004-01-06 at 11:09, Raoul Gough wrote:
>>> Jonathan Brandmeyer <jbrandmeyer at earthlink.net> writes:
>>>
>>> > I have written a new implementation for free-standing slice objects.
>>> > This allows you to create and query slice objects that include a
>>> > step-size, as well as export a form of __getitem__ and/or __setitem__
>>> > that can receive slice arguments and tuples of slice arguments.
>>>
>>> Not sure how much overlap there is,
>>
>> It turns out that there isn't much. slice::get_indicies() overlaps with
>> the indexing suite's slicing support, but in a different way such that
>> it might be OK to keep, anyway. My object really just provides a object
>> manager for PySliceObject, rather than provide a container of objects
>> initialized by a slice (such as the indexing_suite does).
>
> It sounds like the interfaces may be quite different, but isn't the
> functionality the same?
Not exactly, IMO.
> Once you have a Python slice object, you
> can use this to access portions of a container via __getitem__ from
> the indexing suite.
Yeah, or any other Python object that supports slicing.
> On the other hand, if the slice object is actually one
> of your python::slice objects, you could use its get_indices member
> function to access parts of a container as well.
You don't need get_indices:
>>> range(10)[slice(2,6)]
[2, 3, 4, 5]
>>> range(10)[slice(2,6,2)]
[2, 4]
Therefore:
object slice262(object x)
{
return x[slice(2,6,2)]
}
Ought to work. But since there are no tests or examples I don't
understand how get_indices is supposed to be used.
> What I should probably also have said in my original message is that
> I'm working on a new version of the indexing suite. It certainly fixes
> some of the issues you've identified - have a look for indexing_v2 in
> the archives or see http://home.clara.net/raoulgough/boost/. There are
> actually a lot of different issues in providing sensible __getitem__
> support for C++ containers (for example, take a look at the proxy
> support in Joel's suite, or the container_proxy wrapper in mine).
>
> Please not that I'm not trying to put you off contributing code! I
> just think it doesn't make sense to duplicate functionality, so you
> should probably be aware of the existing work taking place in this
> area.
Having a slice object seems highly valuable to me. I don't know if
get_indices really belongs in it, but I'll need to hear more from
Jonathan. I hope the two of you can put your heads together to
integrate whatever overlapping work you may be pursuing.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list