[PATCH] D26332: Add a user-defined literal for StringRef

Chandler Carruth via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 22 15:25:37 PST 2016


chandlerc added a comment.

In https://reviews.llvm.org/D26332#590536, @malcolm.parsons wrote:

> The LLVM coding standards don't mention UDL.
>
> The Google C++ Style Guide says
>  Pro: User-defined literals are a very concise notation for creating objects of user-defined types.
>  Con: User-defined literals allow the creation of new syntactic forms that are unfamiliar even to experienced C++ programmers.
>  Decision: Do not overload operator"", i.e. do not introduce user-defined literals
>
> http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0403r0.html proposes a UDL for std::string_view.
>
> I think the pros outweigh the cons.


FWIW, I disagree.

I think that UDLs introduce a surprising and novel syntax for calling functions. If there is an overwhelming desire to add UDLs for StringRef, we could do so, but so far I find the benefit provided relatively small and increasing the syntax scope of the language a high price to pay.

For example, in the overwhelming majority of the cases in this patch, I suspect the construction of the StringRef could be skipped entirely, and at most some missing overloads added to cause the code to work as-is without any need for further syntactic contortions.


https://reviews.llvm.org/D26332





More information about the llvm-commits mailing list