|
Boost : |
Subject: Re: [boost] Heads up - string_ref landing
From: Rob Stewart (robertstewart_at_[hidden])
Date: 2012-12-13 05:43:07
On Dec 12, 2012, at 6:48 PM, Jeffrey Yasskin <jyasskin_at_[hidden]> wrote:
> 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]>
>>> wrote:
>>>> o char const (&)[N]
>>>
>>> This constructor is dangerous in cases like
>>>
>>> char space[100];
>>> 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?
I didn't follow that part very carefully, it seems, if your summary is correct. I do think it is important to be able to use an entire array, so from_array() would be useful apart from from_literal().
> Then I suggested that from_literal might be replaced by a C++11 UDL, but you ignored that part of my email.
Since I know almost nothing about UDLs, what should I have done differently?
___
Rob
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk