lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] constevalification [Was: PATCH: simple clang -Wuninitialized-const


From: Greg Chicares
Subject: [lmi] constevalification [Was: PATCH: simple clang -Wuninitialized-const-reference fix]
Date: Thu, 29 Apr 2021 01:20:46 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0

On 4/28/21 11:14 PM, Vadim Zeitlin wrote:
> On Wed, 28 Apr 2021 22:58:59 +0000 Greg Chicares <gchicares@sbcglobal.net> 
> wrote:
[...]
> GC> Surely some lmi functions should be consteval;
> GC> I'm thinking of nonstd::power(T x, int n), at least for the
> GC> cases we really care about:
> GC>   double x = 2.0
> GC>   double x = 10.0
> GC> (where I was recently tempted to introduce lookup tables,
> GC> but that would be a terrible mistake if we can consteval
> GC> something like the existing code);
> 
>  I think we can and it there is no need to wait for constexpr-ifying
> everything else in order to do it. Should I add a (higher priority) task
> for this

It's a good thing to do, but probably a lower priority
than constexpr-everywhere-ification.

> or would you prefer to try doing it yourself?

That's a temptation that I must strive to resist.

> GC> and also this thing:  
> GC> 
> GC>     std::string look_up_scale_unit(int decimal_power)
> GC>         {
> GC>         return
> GC>              ( 0 == decimal_power) ? ""
> GC>             :( 3 == decimal_power) ? "thousand"
> GC>             :( 6 == decimal_power) ? "million"
> GC>             :( 9 == decimal_power) ? "billion"
> GC>             :(12 == decimal_power) ? "trillion"
> GC>             :(15 == decimal_power) ? "quadrillion"
> GC>             :(18 == decimal_power) ? "quintillion"
> GC>             : throw std::logic_error("Unnamed scaling unit.")
> GC>             ;
> GC>         }
> 
>  I'm not even sure off hand (and too tired to look it up) if you can throw
> from a consteval function. But I'm pretty sure you should be able to static
> assert when evaluating it in a compile-time context, i.e. it could be
> rewritten with a chain of "if constexpr" if necessary.

It would be interesting to explore those ideas. Practically
speaking, though, this takes about one microsecond per
illustration, so it's not worth optimizing for its own sake.
However, if we could invent a generic consteval lookup
component, we'd probably find other uses for it.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]