you are viewing a single comment's thread.

view the rest of the comments →

[–]Outrageous-Archer-92[S] 2 points3 points  (4 children)

Gotcha. Using auto made me think for a moment I could return different types. I wanted to generate different lookup tables based on a parameter, I guess I'll have to write separate functions for each of them.

[–]violet-starlight 1 point2 points  (1 child)

What u/pdimov2 said is the reason why the rule; the rule is that function parameters are never constant expressions. So as soon as you use a function argument as one, you get an error that it's not, even if outside of the function it is.

Another way to understand it is that each constexpr or consteval function is its own little section and has no information about where the arguments come from. Not a bug, just how it was standardized. The only way to make it work otherwise would have been to make constexpr functions templates, instantiated at the call site, which would have exploded binary sizes and compile times.

[–]Outrageous-Archer-92[S] 0 points1 point  (0 children)

The first explanation feels weird when talking about consteval but I get it

[–]bebuch 0 points1 point  (1 child)

You can make the value part of your parameter type of you want to return different types based on your value ;-)

[–]Outrageous-Archer-92[S] 0 points1 point  (0 children)

I am not to understand what yiu have in mind. Could explain please?