Re: [PATCH] SBufList

From: Alex Rousskov <rousskov_at_measurement-factory.com>
Date: Mon, 02 Dec 2013 08:10:40 -0700

On 12/02/2013 05:23 AM, Kinkie wrote:
>> > My point was that joining SBuf containers is useful for all container
>> > types, but your code only works for std::lists. I think you can provide
>> > the same functionality, with the same level of optimization, by making
>> > the code generic. Here is a sketch:
>> >
>> > {
>> > SBuf::size_type mergedSize = 0;
>> > std::accumulate(..., mergedSize, AddSize(separator));
>> >
>> > SBuf merged;
>> > merged.reserveSpace(mergedSize);
>> > std::accumulate(..., merged, AddContent(separator));
>> >
>> > return merged;
>> > }
>> >
>> > The missing "..." parts just contain items.begin(), items.end(), where
>> > bufs is the container.

> Ok.
> Let's try to sketch the grand plan, shall we?
> What about using a SBufAlgs.h which contains
>
> SBufEqual
> SBufStartsWith
> SBufAddLength(separator=SBuf())

Sounds good to me. I do not think you need a default value for the
separator in the SBufAddLength.

AFAICT, You will also need an SBufAddContent class "operator" with the
following constructor (similar to SBufAddLength):

SBufAddContent::SBufAddContent(const SBuf &separator);

And, if you insist that IsMember() wrapper is needed, it can be placed
in the same header file as well. Make it generic like the SBufJoin() below.

> template<class container> SBufContainerJoin<container>(...)

This one will be more like

template<class Container>
SBuf
SBufJoin(const Container &items, ...)
{
    ... see the sketch above ...
}

> plus a specialized SBufListJoin which is simply an instantiation of
> SBufContainerJoin<SBufList>?

What will that specialization do differently? I do not think we need it
but perhaps I am missing something.

Thank you,

Alex.
Received on Mon Dec 02 2013 - 15:11:00 MST

This archive was generated by hypermail 2.2.0 : Mon Dec 02 2013 - 12:00:08 MST