Skip to content

allow to use reflection in constant time evaluation#8978

Open
fdr400 wants to merge 2 commits intogoogle:masterfrom
fdr400:patch-1
Open

allow to use reflection in constant time evaluation#8978
fdr400 wants to merge 2 commits intogoogle:masterfrom
fdr400:patch-1

Conversation

@fdr400
Copy link

@fdr400 fdr400 commented Mar 13, 2026

It is useful for constexpr switch cases, for example, using magic_enum::enum_switch

Example from our code base:

::parquet::schema::NodePtr makeNode(const ::reflection::Field& field) {
  const auto name = field.name()->str();

  return magic_enum::enum_switch(
      [&name](auto val) -> ::parquet::schema::NodePtr {
        constexpr auto base_type = val;
        if constexpr (::reflection::IsScalar(base_type)) { // <- must be constexpr to be evaluated
          return makeScalarSchema<ToCppNativeType<base_type>>(name);
        } else if constexpr (base_type == ::reflection::BaseType::String){
          return makeStringSchema<std::string>(name);
        } else {
          static_assert(false);
        }
      },
      field.type()->base_type());
}

allow to use reflection in constant time evaluation
@fdr400 fdr400 requested a review from dbaileychess as a code owner March 13, 2026 09:04
@google-cla
Copy link

google-cla bot commented Mar 13, 2026

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.

@github-actions github-actions bot added the c++ label Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant