Açıklaması şöyle
There are 3 kinds of functions in C++, and is_constant_evaluated only makes sense in one of them.
Şöyle yaparız
// a strictly run-time function
int foo(int arg) 
{
    if (std::is_constant_evaluated()) // pointless: always false
        // ...
}
// a strictly compile time function
consteval int foo(int arg) 
{
    if (std::is_constant_evaluated())  // pointless: always true
        // ...
}
// both run-time and compile-time
constexpr int foo(int arg) 
{
    if (std::is_constant_evaluated())  // ok: depends on context in 
                                       // which `foo` is evaluated
        // ...
}
Hiç yorum yok:
Yorum Gönder