From Jason Turner
Watch on YouTube

Summary

This episode explores the C++20 feature `std::is_constant_evaluated()` from the header. Jason demonstrates how this function allows code to detect whether it's being executed during compile-time constant evaluation or at runtime. He explains the key differences between `if constexpr` and `if (std::is_constant_evaluated())`, showing that the latter enables different code paths for constant evaluation versus runtime execution in the same function. This capability is particularly useful for implementing functions that need optimized compile-time versions alongside potentially more efficient runtime implementations.

Resources

Tags