Re: [PATCH] SBufList

From: Kinkie <gkinkie_at_gmail.com>
Date: Mon, 2 Dec 2013 19:34:00 +0100

On Mon, Dec 2, 2013 at 4:10 PM, Alex Rousskov
<rousskov_at_measurement-factory.com> wrote:
> 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);

Done.

> 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.

It's just convenience.
I'd leave SBufList.h / .cc only as convenience helpers, relying on
SBufAlgos.h for some grunt work.

>> 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.

As above: just convenience, or an intermediate step towards complete
containerization (c->c++ will be hard enough as is, as it will require
to have callers use correct encapsulation)

Attaching a new revision.

-- 
    /kinkie

Received on Mon Dec 02 2013 - 18:34:08 MST

This archive was generated by hypermail 2.2.0 : Tue Dec 03 2013 - 12:00:11 MST