C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: 2 big problems with User Defined literals:
From: Andy Little (kwikius_at_[hidden])
Date: 2021-05-07 09:08:45


On Thursday, 6 May 2021, 15:10:01 BST, Jason McKesson via Std-Discussion <std-discussion_at_[hidden]> wrote:
> It can be made available as a template parameter. Unsynthesized UDLs
> exist; they take the UDL as a variadic sequence of `char`s. They're
> much harder to parse, but they are functional solutions.

> The simplest solution here (that requires no language changes) is to
> make a pair of library `consteval` template functions that take the
> sequence of chars and returns a synthesized value; one for integers,
> one for floats. This value would be `constexpr`, so it could be used
> to determine the result type of the function.

Thanks for that. I didn't figure out how this works before.

I did a rough and ready test which I put here  for those interested. I hope long term to incorporate it into my library properly

https://github.com/kwikius/pqs/blob/master/examples/bespoke_user_defined_literal.cpp

------------

> UDLs are for when space is at a premium, wordiness is really bad, and
> the resultant meaning of the code ought to be obvious.

Sure, but that is basically always.

> Adding namespaces to literals like this (even if the parser could do it)
> means that you're willing to spell things out.

UDLs is a potentially nice language feature, but is inflexible. Currently UDLs can't be qualified, so they can only be used in global namespace.
The problem as shown by the ad hoc rule that UDLs without underscore are reserved.
Yet already there are potential collisns in std namespace between units libray proposal http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1935r2.html
and std::chrono literals


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups