Boost logo

Boost :

Subject: Re: [boost] Heads up - string_ref landing
From: Rob Stewart (robertstewart_at_[hidden])
Date: 2012-12-12 07:49:59


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.

___
Rob


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