5 ms·
I must be missing something here, because my first thought was "Any constexpr must be const all the way down." Meaning: - Constexpr objects must be fully const
by kstenerud 2y ago
I must be missing something here, because my first thought was "Any constexpr must be const all the way down." Meaning:
- Constexpr objects must be fully const (i.e. they cannot be modified, and non-const methods are not allowed to be called).
- Constexpr objects cannot allow access to mutable data (directly or indirectly). Maybe this is where the devil is in the details? Not sure... It seems that pointers to mutable via constexpr would be a niche thing anyway.
- Constexpr objects always exist for the duration of the program.
- Any allocations made during construction are done via a "const pool" allocator that no-ops deallocation, so that nothing blows up at shutdown. If everything is const/constexpr, the total allocation size should be decidable at compile time, I think?
- keybored 2y agoDoes “const” mean “immutable” and “constexpr” mean “compile-time” in C++? That’s funny.
- kstenerud 2y agoconstexpr 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.
- keybored 2y agoI 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.