[llvm] r187166 - Add a bool->StringRef c'tor to StringRef.

David Blaikie dblaikie at gmail.com
Fri Jul 26 11:43:10 PDT 2013


On Fri, Jul 26, 2013 at 11:35 AM, Bill Wendling <isanbard at gmail.com> wrote:
> On Jul 26, 2013, at 11:31 AM, David Blaikie <dblaikie at gmail.com> wrote:
>
>> On Thu, Jul 25, 2013 at 4:06 PM, Bill Wendling <isanbard at gmail.com> wrote:
>>> Author: void
>>> Date: Thu Jul 25 18:06:39 2013
>>> New Revision: 187166
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=187166&view=rev
>>> Log:
>>> Add a bool->StringRef c'tor to StringRef.
>>
>> FWIW I was more expecting this to be a free function - not sure it
>> really deserves to be a StringRef ctor, even if it's explicit. Would
>> make the usage of this a little bit subtle. A "toString" or something
>> might be a bit more legible.
>>
>> Not going to make any absolute claims here, so do whatever you think
>> is best - just thoughts.
>>
> Do you mean something like this?
>
> StringRef boolToStringRef(bool B) {
>   return StringRef(B ? "true" : "false");
> }

Yep - toStringRef is probably fine (C++11 got a to_string so people
didn't have to go through streams to get a stringified version of some
object & could overload that with all the fun things they want to
convert, so having "toStringRef" seems consistent with that -
documents the conversion but doesn't necessarily have to have the
source type enshrined there, overloading is fine). Just slightly less
confusing than "what does this StringRef ctor that takes a bool do?"



More information about the llvm-commits mailing list