Subject: Re: [boost] Heads up - string_ref landing
From: Jeffrey Yasskin (jyasskin_at_[hidden])
Date: 2012-12-12 18:48:22
On Wed, Dec 12, 2012 at 4:49 AM, Rob Stewart <robertstewart_at_[hidden]> wrote:
> On Dec 10, 2012, at 4:16 PM, Jeffrey Yasskin <jyasskin_at_[hidden]> wrote:
>> On Wed, Nov 28, 2012 at 2:48 AM, Rob Stewart <robertstewart_at_[hidden]>
>>> o char const (&)[N]
>> This constructor is dangerous in cases like
>> char space;
>> snprintf(space, 100, "format", args);
>> string_ref str(space);
>> so I think most of the suggestions on this list have moved toward a more
>> explicit but very verbose string_ref::from_literal("foo\0bar").
> Misuse is the user's fault, of course, but I understand the value of enlisting the compiler's help and making things verbose to turn mistakes into errors or to make them more obvious.
> In your example, from_literal() is incorrect as the construction should be from a char * (after array to pointer decay), with an implicit strlen(), not from a string literal. So, I think you meant that from_array() should replace the referenced constructor so string_ref(char const *) matches the call in your example instead. That's a reasonable change.
I don't understand this paragraph. I was saying that the suggestions
on this list were tending toward string_ref("foo\0bar").size()==3 and
string_ref::from_literal("foo\0bar").size()==7. I'm not clear on what
people intend string_ref::from_array("foo\0bar") to do, but maybe it
includes the trailing \0? Then I suggested that from_literal might be
replaced by a C++11 UDL, but you ignored that part of my email.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk