COMMON/MATH: Add some constexpr constructors to Array/List/String/Rect and the Matrix base-classes. #4910
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While working on some code that had a large amount of global variables, I wanted to get rid of the global constructor warnings that ensued once I started to use our collections/string classes in these global variables. While the globals will eventually go away in my codebase, there are also constants that would benefit from not having to run constructors.
After having a bit of a look, it seems that as long as there is a constexpr constructor available (which requires that all members are also constexpr-constructible), we can avoid global constructors.
So this is a quick attempt at adding constexpr constructors to the above mentioned classes, as well as the beginnings of supporting this in the Matrix classes as well, however the Matrix attempt is currently blocked by the logic for initializing with the identity matrix, as calling setToIdentity() triggers a warning about this being a C++14 extension.
Similarly the constructor for Common::String has to use an initializer list for the storage array, for which I've seen some comments on StackOverflow that mention that initializing arrays in the initializer list might have problems in some versions of MSVC.
This needs a fair bit of testing across compilers to be sure it doesn't break the compile on some platform, and the overall benefit boils down to being able to create compile time constants of classes that contain these classes.