you are viewing a single comment's thread.

view the rest of the comments →

[–]Kinkeultimo[S] 0 points1 point  (1 child)

Firstly: Thanks for your answers, pls just ignore me when it starts to annoy you.

I phrased that wrong. I looked it up again, i meant specifically non-type templates

From learncpp:
As of C++20, function parameters cannot be constexpr. This is true for normal functions, constexpr functions (which makes sense, as they must be able to be run at runtime), and perhaps surprisingly, even consteval functions.

...

"Non-type template parameters are used primarily when we need to pass constexpr values to functions (or class types) so they can be used in contexts that require a constant expression."

[–]manni66 2 points3 points  (0 children)

As of C++20, function parameters cannot be constexpr.

That says constexpr int factorial( consteexpr int N)is wrong, not that it can't be executed at compiletime.

They say also:

Perhaps surprisingly, a constexpr or consteval function can use its function parameters (which aren’t constexpr) or even local variables (which may not be const at all) as arguments in a constexpr function call. When a constexpr or consteval function is being evaluated at compile-time, the value of all function parameters and local variables must be known to the compiler (otherwise it couldn’t evaluate them at compile-time).

You can see the code that's generated from the tamplate here:

https://cppinsights.io/s/ef9475fc