#virtual constexpr
1045 messages · Page 2 of 2 (latest)
not in literally any other case
and yes, you should still use constexpr here
the fact that this works at all is a relic from times where constexpr was not a thing but people wanted to be able to not have to use #define for defining an array size basically
even C has constexpr nowadays for at least variables
well, it will have
and i've been lookking for such a case or two. Perhaps a function returning an array size being one?
I think we've provided lots of examples honestly lol
constexpr float blub = 69.42f;
template <float f> void fun();
fun<blub>();
there you go
this does not work with const
<source>:10:6: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'f'
template<float f>
void fun()
{
}
int main()
{
constexpr float ff = 3.4f;
fun<ff>();
return 0;
}
its always been a bit weird with floats
dot may be able to tell
why are you using gcc 10.4?
you can use a latest version of clang too
clang seems to not support this yet. it's a C++20 feature…
¯_(ツ)_/¯
it should work on gcc and msvc
yea
clang has the weirdest template support
fair, so this works only cause templates are evaluated at compile time and const float isn't hence the error?
another clang bug
surprising
template arguments must be constant expressions. and a const float is not usable in a constant expression.
hm and only integral const values are usage in a constant expression right?
integral and enumeration types
and you ideally forget that's even a thing and just use constexpr
because it's just a legacy thing anyways
alright thanks dot. appreciate it. the last example was helpful
👍
@wintry agate Has your question been resolved? If so, run !solved :)
!solved