Skip to content

Added rfl::DefaultVal, resolves #534#553

Merged
liuzicheng1987 merged 10 commits into
mainfrom
f/default
Dec 5, 2025
Merged

Added rfl::DefaultVal, resolves #534#553
liuzicheng1987 merged 10 commits into
mainfrom
f/default

Conversation

@liuzicheng1987
Copy link
Copy Markdown
Contributor

No description provided.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @liuzicheng1987, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces the rfl::DefaultVal mechanism, significantly enhancing the rfl library's deserialization capabilities by allowing struct fields to be initialized with default values when they are absent in the input data. This feature addresses the common need to provide fallback values for optional fields, improving robustness and reducing boilerplate code. The changes involve adding the DefaultVal wrapper type, updating the parsing logic to respect these default values, and introducing new compile-time traits for introspection. The has_tag_v trait was also modernized using C++20 concepts.

Highlights

  • New rfl::DefaultVal Type: Introduced a new C++ template struct rfl::DefaultVal<T> that allows fields in reflected structs to specify a default value, which will be used if the field is missing during deserialization.
  • Updated Parsing Logic: The NamedTupleParser has been enhanced to correctly handle rfl::DefaultVal fields. These fields are no longer considered 'required' if absent in the input, and their default values are automatically applied.
  • C++20 Concepts for has_tag_v: The has_tag_v trait, used for tagged unions, has been refactored to leverage C++20 concepts, improving compile-time checks and code clarity.
  • New Internal Traits: Two new internal traits, is_default_val_v and has_default_val_v, were added to enable compile-time detection of DefaultVal types and structs containing them, respectively.
  • Comprehensive Testing: New test cases have been added for JSON serialization and deserialization, covering both standard field-named objects and stripped-field-name arrays, to thoroughly validate the behavior of rfl::DefaultVal.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces rfl::DefaultVal, a useful feature for providing default values for fields during parsing. The implementation is mostly solid, with good test coverage for both standard and no-field-name scenarios. I've identified a few areas for improvement in rfl::DefaultVal.hpp, including a bug in a move assignment operator, some inefficiencies in constructors, and opportunities to modernize the code using C++20 concepts for better consistency and readability. My detailed comments and suggestions are provided below.

Comment thread include/rfl/DefaultVal.hpp
Comment on lines +29 to +30
DefaultVal(const DefaultVal<U>& _field) : value_(_field.get()) {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This unconstrained converting copy constructor is redundant with the constrained version on lines 42-44. Having both can lead to ambiguity during template resolution. It would be safer to remove this one and rely solely on the constrained version.

Comment thread include/rfl/DefaultVal.hpp Outdated
Comment thread include/rfl/DefaultVal.hpp Outdated
liuzicheng1987 and others added 8 commits December 3, 2025 23:07
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@liuzicheng1987 liuzicheng1987 merged commit 192a74e into main Dec 5, 2025
291 of 292 checks passed
@liuzicheng1987 liuzicheng1987 deleted the f/default branch January 24, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant