#What is constexpr?

29 messages ยท Page 1 of 1 (latest)

glad brookBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

blissful pilot
#

@astral pivot

astral pivot
#

quoting myself from the text channel:
constexpr is used to declare variables whose value is known at compilation, or functions whose calls can be evaluated entirely during compilation
basically it allows you to spare runtime costs by hardcoding things without actually hardcoding them, kinda

#

it's powerful but it comes with constraints, not everything can be a compile-time constant

#

where/why do you need to use it?

blissful pilot
#

it caught my eye in a video of AngeTheGreat

astral pivot
#

yeah

#

you can think of constexpr as const on steroids

#

it's not accurate and doesn't paint the whole picture but if you need to ask it's good enough that you think of it in these terms

blissful pilot
astral pivot
#

yes, because 3.14f is a value known at compile-time it can be assigned to a constexpr value

blissful pilot
#

this gud sht

mild sorrel
#

a bit pedantic, but constexpr isn't about compile time vs runtime, it's about constant expressions, which is how the standard specifies it

astral pivot
#

sure, though compile-time vs runtime is mostly how it manifests and I thought this would be a good approximation to make sense of

#

thanks for bringing that in though ๐Ÿ‘

blissful pilot
#

well, I am mentally unhinged enough not to understand the mechanics of this language, but good way to torture myself with exams up head

astral pivot
#

don't worry, everyone in this server went through that ๐Ÿ˜›

mild sorrel
#

and still do haha

#

C++ is a constant "wait, what the fuck is that?"

blissful pilot
astral pivot
#

@blissful pilot do you want to have a look at the code you posted in the text channel? there's room to improve it

#

if you don't want or prefer to figure it out yourself it's fine too

#

don't hesitate to ask more questions if needed

#

(yes I'm at work and bored out of my f*cking mind)

blissful pilot
astral pivot
#

lol

#

I've seen worse ways to procrastinate

glad brookBOT
#

@blissful pilot

Please Do Not Delete Posts!

Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.

blissful pilot
#

!solved