Explicit conversion of SmallString to std::string

David Blaikie dblaikie at gmail.com
Wed Oct 15 08:46:38 PDT 2014


On Wed, Oct 15, 2014 at 8:40 AM, Yaron Keren <yaron.keren at gmail.com> wrote:

> SmallString has implicit conversion to StringRef:
>
>  operator StringRef() const { return str(); }
>
> Explicit .str() helps when you want to use one of the StringRef useful
> member functions without using an explicit StringRef temporary, such as:
>
>   SmallString<128> Name;
>   if (Name.str().startswith("blah"))
>

Perhaps we could transform these instances to
StringRef(Name).startswith("blah") ? I'm not sure.


>
> StringRef does not have a constructor from SmallString probably to avoid
> circular dependency.
>
> BTW, .str() is already inconsistent since SmallString.str() is StringRef
> but StringRef.str() is std::string.
>
> As for name, would SmallString.to_string() be better?
>

Maybe (modulo our rather mixed attitudes towards naming conventions
(to_string, toString, etc)).

Anyway - I just wanted to bring up the 'string' being a slightly
contentious name. I'd like some other voices on this thread & don't mean to
take "ownership" of the review here.


>
>
> 2014-10-15 18:12 GMT+03:00 David Blaikie <dblaikie at gmail.com>:
>
>> using the same identifier as a standard type like 'string' is probably a
>> bit sketchy... though I'm not sure what other names might suit
>>
>> Why does SmallString need an explicit StringRef-izing function anyway
>> (thus freeing up the name 'str')? That seems like a reasonable implicit
>> conversion that'd rarely be needed to be explicit... but perhaps I'm wrong.
>
>
> On Wed, Oct 15, 2014 at 2:53 AM, Yaron Keren <yaron.keren at gmail.com>
> wrote:
>
>> SmallString conversion to std::string is currently done by going through
>> a StringRef, S.str().str(). This patch provides a direct conversion
>> function, S.string().
>>
>> Yaron
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141015/fb052e37/attachment.html>


More information about the llvm-commits mailing list