allow to use reflection in constant time evaluation#8978
allow to use reflection in constant time evaluation#8978jtdavis777 merged 6 commits intogoogle:masterfrom
Conversation
allow to use reflection in constant time evaluation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
should we look at any other functions in this file to mark constexpr? We just need to keep C++11 compatible. |
|
@jtdavis777 thanks for review! Yes, it is possible. I made two more functions constexpr. I believe no more functions in the file can be converted to constexpr because of C++11 limitations |
|
is it required to place the constexpr array outside the function for c++11? it's probably fine to expose that, but I'd prefer if we didn't |
|
@jtdavis777 unfortunately, yes( Alternative solution is constexpr size_t GetTypeSize(reflection::BaseType base_type) {
return
base_type == reflection::None ? 0 :
base_type == reflection::UType ? 1 :
base_type == reflection::Bool ? 1 :
base_type == reflection::Byte ? 1 :
base_type == reflection::UByte ? 1 :
base_type == reflection::Short ? 2 :
base_type == reflection::UShort ? 2 :
base_type == reflection::Int ? 4 :
base_type == reflection::UInt ? 4 :
base_type == reflection::Long ? 8 :
base_type == reflection::ULong ? 8 :
base_type == reflection::Float ? 4 :
base_type == reflection::Double ? 8 :
base_type == reflection::String ? 4 :
base_type == reflection::Vector ? 4 :
base_type == reflection::Obj ? 4 :
base_type == reflection::Union ? 4 :
base_type == reflection::Array ? 0 :
base_type == reflection::Vector64 ? 8 :
0; // MaxBaseType / fallback
}but it looks a bit awkward, I guess.. |
|
Yeah that is t worth it. I thinks it is good as is. |
It is useful for constexpr switch cases, for example, using
magic_enum::enum_switchExample from our code base: