#virtual constexpr

1045 messages · Page 2 of 2 (latest)

gritty saddle
#

and I'd still use constexpr

tender grove
#

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

narrow wave
#

even C has constexpr nowadays for at least variables

tender grove
#

well, it will have

wintry agate
gritty saddle
#

I think we've provided lots of examples honestly lol

tender grove
#
constexpr float blub = 69.42f;

template <float f> void fun();

fun<blub>();
#

there you go

#

this does not work with const

wintry agate
#

<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;
}
native kindle
#

what version

#

this is fine

wintry agate
#

20

#

'float' is not a valid type for a template non-type parameter

native kindle
#

thats not a 20 error

#

but it doesnt seem to work on clang

#

interesting

wintry agate
native kindle
#

its always been a bit weird with floats

wintry agate
#

dot may be able to tell

tender grove
#

why are you using gcc 10.4?

wintry agate
#

you can use a latest version of clang too

tender grove
wintry agate
#

so there's a bug in clang?!

#

jeez

tender grove
#

clang seems to not support this yet. it's a C++20 feature…

#

¯_(ツ)_/¯

#

it should work on gcc and msvc

native kindle
#

clang has the weirdest template support

wintry agate
#

fair, so this works only cause templates are evaluated at compile time and const float isn't hence the error?

narrow wave
#

another clang bug australianblaze surprising

tender grove
wintry agate
#

hm and only integral const values are usage in a constant expression right?

tender grove
#

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

gritty saddle
#

We're almost there, 30 messages more

#

And we made history of standardese

wintry agate
#

alright thanks dot. appreciate it. the last example was helpful

tender grove
#

👍

onyx brambleBOT
#

@wintry agate Has your question been resolved? If so, run !solved :)

wintry agate
#

!solved