Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Does “const” mean “immutable” and “constexpr” mean “compile-time” in C++? That’s funny.


constexpr was originally intended for "things that can be computed at compile time". But for something to be computable at compile-time, it would have to also be immutable.


I can imagine a for loop with `i` which computes something over a static value where `i` isn’t immutable but is needed to compute the “constexpr” value.


But if `i` changes over time, then it can't be computed at compile time, because its value is dependent upon at what time it is accessed.


Looping over the calendar months seems to make sense to me.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: