Yes, const fn acts like C++'s constexpr function in some cases.
You can force to call to happen at compiletime by assigning the result to a const or using it in a const context.
when I use the function foo, the compiler report me that:
error[E0401]: can't use generic parameters from outer function
--> src/main.rs:8:25
|
7 | pub fn foo<const tail: u32, const head: u64>() -> u64 {
| ---- const parameter from outer function
8 | const I: u64 = test(tail, head);
| ^^^^ use of generic parameter from outer function
and if I use bar:
error[E0435]: attempt to use a non-constant value in a constant
--> src/main.rs:13:25
|
13 | const I: u64 = test(tail, head);
| ------- ^^^^ non-constant value
| |
| help: consider using `let` instead of `const`: `let I`
I don't find any pattern that mark a parameter as a const.
Your bar function definitely wont be possible to get to work. The value of tail and head are not guaranteed to be constant. You can get foo to compile like this: