Questions tagged [consteval]

consteval is a modifier introduced in C++20, which informs the compiler that the function is immediate - it can only be calculated at compile time. It is similar to modifier constexpr but it enforces compile time evaluation, not only allows it.

79 questions
0
votes
1 answer

Constantly inlining a function with a consteval call

I have a consteval crc32 function that works just fine on compile time. I want this function to be used in another constant inline function. Here is a code example for a better understanding: unsigned int consteval strsum(const std::string str) { …
Artemking4
  • 31
  • 7
0
votes
1 answer

Changing constexpr to consteval results in unintelligible error message in MSVC. Compiler bug or questionable code?

I have the following template / compile-time utility helper functions. It works fine in all three compilers (MSVC, GCC, clang) when everything is constexpr, but changing a few bits to consteval results in an odd error in MSVC. I want to migrate all…
Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
0
votes
3 answers

Can consteval functions from different translation units interfere?

I am trying to dig into implications of a function being inline and stumbled upon this issue. Consider this small program (demo): /* ---------- main.cpp ---------- */ void other(); constexpr int get() { return 3; } int main() { std::cout…
Mikhail
  • 20,685
  • 7
  • 70
  • 146
-1
votes
1 answer

C++ metaprogramming vs compiler optimization

The toy problem of recursive (non-caching) fibonacci can be implemented as following: #include int fibonacci(int n) { if (n <= 1) return n; else return fibonacci(n - 1) + fibonacci(n - 2); } int main() { int…
user23952
  • 578
  • 3
  • 10
1 2 3 4 5
6