Malcolm Parsons via llvm-dev
2016-Nov-29 10:20 UTC
[llvm-dev] RFC: Constructing StringRefs at compile time
On 28 November 2016 at 20:51, Zachary Turner via llvm-dev <llvm-dev at lists.llvm.org> wrote:> The basic idea here is that you introduce a StringLiteral class and anywhere > you want to use a global constructor, you make sure to declare a constexpr > array instead of a normal array, and you make it of type StringLiteral.I prefer constexpr llvm_strlen() over StringLiteral because it doesn't require code changes outside StringRef - all StringRefs constructed from a literal can benefit. But there are concerns about MSVC. I prefer StringLiteral over UDL because the type requires code changes, but the values don't. I prefer StringLiteral over explicit StringRef constructor because it's safer. -- Malcolm Parsons
Zachary Turner via llvm-dev
2016-Nov-29 16:18 UTC
[llvm-dev] RFC: Constructing StringRefs at compile time
I don't like the llvm_strlen approach as it is incompatible with std::string_view which we may eventually move to. StringLiteral will still interoperate nicely On Tue, Nov 29, 2016 at 2:20 AM Malcolm Parsons <malcolm.parsons at gmail.com> wrote:> On 28 November 2016 at 20:51, Zachary Turner via llvm-dev > <llvm-dev at lists.llvm.org> wrote: > > The basic idea here is that you introduce a StringLiteral class and > anywhere > > you want to use a global constructor, you make sure to declare a > constexpr > > array instead of a normal array, and you make it of type StringLiteral. > > I prefer constexpr llvm_strlen() over StringLiteral because it doesn't > require code changes outside StringRef - all StringRefs constructed > from a literal can benefit. But there are concerns about MSVC. > I prefer StringLiteral over UDL because the type requires code > changes, but the values don't. > I prefer StringLiteral over explicit StringRef constructor because it's > safer. > > -- > Malcolm Parsons >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161129/d1c99052/attachment.html>
Malcolm Parsons via llvm-dev
2016-Nov-29 16:31 UTC
[llvm-dev] RFC: Constructing StringRefs at compile time
On 29 November 2016 at 16:18, Zachary Turner <zturner at google.com> wrote:> I don't like the llvm_strlen approach as it is incompatible with > std::string_view which we may eventually move to.In what way is it incompatible? constexpr StringRef(const char* s) : Data(s), Length(llvm_strlen(s)) {} is equivalent to constexpr string_view(const char* s) : Data(s), Length(std::char_traits<char>::length(s)) {} -- Malcolm Parsons