Boost logo

Boost :

Subject: Re: [boost] Heads up - string_ref landing
From: Rob Stewart (robertstewart_at_[hidden])
Date: 2012-12-09 08:13:20


On Dec 6, 2012, at 8:18 AM, Sergey Cheban <s.cheban_at_[hidden]> wrote:

> On 28.11.2012 14:48, Rob Stewart wrote:
>
>> OK, I suspect we're agreeing more than disagreeing. Here's the I/F of my string_ref:
>>
>> - converting ctors from:
>> o char const *
>> o std::string const &
>> o std::vector<char> const &
>> o const_substring const & (my substring type)
>> - other ctors:
> What about default constructor?

Yes

>> o char const *, size_t
>> o char const *, char const *
>> o char const (&)[N]
> May be, it is reasonable to add bool trim_last = true here? This would allow not null-terminated character arrays.

I can see value in that.

>> - similar assignment operators
>> - similar assign() member functions
>> - bool is_null()
> I propose empty() instead. I don't think that the substring (and especially string_REF) may be "null".

I suppose it should be empty(), though I hate that it isn't the right part of speech. That is, "empty" should be synonymous with "clear". Still, consistency with std::string should probably take precedence.

>> - safe bool or explicit bool conversion operator
> I don't think this is a good idea.

Why not?

>> - char const * data()
>> - size_t length()
> I propose the alias size().

string_ref isn't a container like string, so I prefer just length().

>> - char const * begin()/end()
> +cbegin/cend.

Ah, yes.

>> - string_ref substr()
>> - char operator[](size_t)
> Throwing at() may be useful, too.

I suppose so.

>> (I think that's a complete list. I'm doing it from memory now.)
> What about pop_back(), pop_front(), swap()?

string_ref isn't a container, so pop_back() and pop_front() are inappropriate. However, back(), front(), and swap() are reasonable.

> And again, I propose "substring" instead of "string_ref".

I also have [const_]substring classes which have a different interface, so I disagree. (There is, of course, some overlap.)

___
Rob


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk