Skip to content

Add operator* and non-const accessors to wrapper classes#603

Merged
liuzicheng1987 merged 2 commits intomainfrom
add-operator-star-to-wrappers-9490559753035774407
Feb 8, 2026
Merged

Add operator* and non-const accessors to wrapper classes#603
liuzicheng1987 merged 2 commits intomainfrom
add-operator-star-to-wrappers-9490559753035774407

Conversation

@liuzicheng1987
Copy link
Contributor

Added operator* and non-const .get() to reflect-cpp wrapper classes for better API convenience and consistency. Updated documentation accordingly.


PR created automatically by Jules for task 9490559753035774407 started by @liuzicheng1987

This commit adds `operator*` (const and non-const) to all reflect-cpp wrapper classes,
including `DefaultVal`, `Field`, `Validator`, `Description`, `Rename`, `Attribute`,
`Flatten`, `Hex`, `Oct`, `Binary`, `Generic`, `Timestamp`, and `internal::Skip`.
Additionally, it ensures that these classes have non-const `.get()`, `.value()`,
and `operator()()` where appropriate, providing consistent access to the underlying value.
Documentation has also been updated to reflect these changes.

Co-authored-by: liuzicheng1987 <19538706+liuzicheng1987@users.noreply.github.com>
@google-labs-jules
Copy link

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link

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 enhances the reflect-cpp library's API by providing more convenient and consistent ways to access the underlying values of its wrapper classes. By introducing operator* and non-const overloads for existing accessor methods like get(), value(), and operator()(), developers can now interact with wrapped objects more intuitively, improving code readability and enabling mutable operations directly through these wrappers.

Highlights

  • New operator* Overload: Introduced operator* for direct dereferencing of underlying values in various reflect-cpp wrapper classes, providing a more pointer-like interface.
  • Non-Const Accessor Overloads: Added non-const overloads for get(), value(), and operator()() methods in several wrapper classes, enabling mutable access to the wrapped objects.
  • Documentation Updates: Updated relevant documentation files (e.g., docs/default_val.md, docs/flatten_structs.md, docs/generic.md) to reflect the new API convenience methods and their usage.
Changelog
  • docs/default_val.md
    • Updated API convenience section to include operator*().
  • docs/flatten_structs.md
    • Added a new 'API convenience' section explaining accessors for rfl::Flatten, including operator*().
  • docs/generic.md
    • Updated description of rfl::Generic accessors to include .value(), operator()(), and operator*().
  • docs/json_schema.md
    • Added a note about rfl::Description API convenience, including operator*().
  • docs/named_tuple.md
    • Added a new 'rfl::Field API convenience' section explaining accessors for rfl::Field, including operator*().
  • docs/number_systems.md
    • Updated accessors for rfl::Hex, rfl::Oct, rfl::Binary to include operator()() and operator*().
  • docs/rfl_skip.md
    • Added an example demonstrating *person.town;.
  • docs/supported_formats/xml.md
    • Added a note about rfl::Attribute API convenience, including operator*().
  • docs/timestamps.md
    • Updated accessors for rfl::Timestamp to include .get(), .value(), operator()(), and operator*().
  • docs/validating_numbers.md
    • Updated accessors for rfl::Validator to include .get(), operator()(), and operator*().
  • include/rfl/Attribute.hpp
    • Added non-const get() overload.
    • Added operator*() (const and non-const overloads).
  • include/rfl/Binary.hpp
    • Added non-const get() overload.
    • Added operator*() (const and non-const overloads).
  • include/rfl/DefaultVal.hpp
    • Added non-const get() overload.
    • Added operator*() (const and non-const overloads).
  • include/rfl/Description.hpp
    • Added non-const get() overload.
    • Added operator*() (const and non-const overloads).
  • include/rfl/Field.hpp
    • Added non-const get() overload.
    • Added operator*() (const and non-const overloads).
  • include/rfl/Flatten.hpp
    • Added operator*() (const and non-const overloads).
    • Added non-const value() overload.
  • include/rfl/Generic.hpp
    • Added non-const get() overload.
    • Added operator*() (const and non-const overloads).
    • Added non-const operator()() overload.
    • Added non-const value() overload.
  • include/rfl/Hex.hpp
    • Added non-const get() overload.
    • Added operator*() (const and non-const overloads).
  • include/rfl/Oct.hpp
    • Added non-const get() overload.
    • Added operator*() (const and non-const overloads).
  • include/rfl/Rename.hpp
    • Added non-const get() overload.
    • Added operator*() (const and non-const overloads).
  • include/rfl/Timestamp.hpp
    • Added non-const get() overload.
    • Added operator*() (const and non-const overloads).
    • Added non-const operator()() overload.
    • Added non-const value() overload.
  • include/rfl/Validator.hpp
    • Added non-const get() overload.
    • Added operator*() (const and non-const overloads).
    • Added non-const operator()() overload.
  • include/rfl/internal/Skip.hpp
    • Added operator*() (const and non-const overloads).
Activity
  • The pull request was automatically generated by Jules for a task initiated by @liuzicheng1987.
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

@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 operator* and non-const .get() accessors to various wrapper classes for improved API convenience and consistency, along with corresponding documentation updates. The changes are generally well-implemented. I've identified a minor formatting issue in one of the documentation files and a few opportunities for code simplification and consistency in the C++ headers by using noexcept and const where appropriate.

Comment on lines 50 to 51
/// Returns the underlying object.
Type& operator*() { return value_; }

Choose a reason for hiding this comment

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

medium

For consistency with other accessor methods and to provide stronger compile-time guarantees, it's good practice to mark methods that do not throw exceptions as noexcept.

Suggested change
/// Returns the underlying object.
Type& operator*() { return value_; }
Type& operator*() noexcept { return value_; }

Comment on lines 53 to 54
/// Returns the underlying object.
const Type& operator*() const { return value_; }

Choose a reason for hiding this comment

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

medium

For consistency with other accessor methods and to provide stronger compile-time guarantees, it's good practice to mark methods that do not throw exceptions as noexcept.

Suggested change
/// Returns the underlying object.
const Type& operator*() const { return value_; }
const Type& operator*() const noexcept { return value_; }

Comment on lines 62 to 63
/// Returns the underlying object.
Type& value() { return value_; }

Choose a reason for hiding this comment

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

medium

For consistency with other accessor methods and to provide stronger compile-time guarantees, it's good practice to mark methods that do not throw exceptions as noexcept.

Suggested change
/// Returns the underlying object.
Type& value() { return value_; }
Type& value() noexcept { return value_; }

Comment on lines 65 to 66
/// Returns the underlying object.
const Type& value() const { return value_; }

Choose a reason for hiding this comment

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

medium

For consistency with other accessor methods and to provide stronger compile-time guarantees, it's good practice to mark methods that do not throw exceptions as noexcept.

Suggested change
/// Returns the underlying object.
const Type& value() const { return value_; }
const Type& value() const noexcept { return value_; }

Comment on lines 56 to 57
/// Returns the underlying object.
VariantType& get() { return value_; }

Choose a reason for hiding this comment

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

medium

For consistency with other accessor methods and to provide stronger compile-time guarantees, it's good practice to mark methods that do not throw exceptions as noexcept.

  VariantType& get() noexcept { return value_; }

Comment on lines 83 to 84
/// Returns the underlying object.
const std::tm& operator*() const { return tm_; }

Choose a reason for hiding this comment

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

medium

For consistency with other accessor methods and to provide stronger compile-time guarantees, it's good practice to mark methods that do not throw exceptions as noexcept.

Suggested change
/// Returns the underlying object.
const std::tm& operator*() const { return tm_; }
const std::tm& operator*() const noexcept { return tm_; }

Comment on lines 86 to 87
/// Returns the underlying object.
std::tm& operator()() { return tm_; }

Choose a reason for hiding this comment

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

medium

For consistency with other accessor methods and to provide stronger compile-time guarantees, it's good practice to mark methods that do not throw exceptions as noexcept.

Suggested change
/// Returns the underlying object.
std::tm& operator()() { return tm_; }
std::tm& operator()() noexcept { return tm_; }

Comment on lines 89 to 90
/// Returns the underlying object.
const std::tm& operator()() const { return tm_; }

Choose a reason for hiding this comment

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

medium

For consistency with other accessor methods and to provide stronger compile-time guarantees, it's good practice to mark methods that do not throw exceptions as noexcept.

Suggested change
/// Returns the underlying object.
const std::tm& operator()() const { return tm_; }
const std::tm& operator()() const noexcept { return tm_; }

Comment on lines 92 to 93
/// Returns the underlying object.
std::tm& value() { return tm_; }

Choose a reason for hiding this comment

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

medium

For consistency with other accessor methods and to provide stronger compile-time guarantees, it's good practice to mark methods that do not throw exceptions as noexcept.

Suggested change
/// Returns the underlying object.
std::tm& value() { return tm_; }
std::tm& value() noexcept { return tm_; }

Comment on lines 95 to 96
/// Returns the underlying object.
const std::tm& value() const { return tm_; }

Choose a reason for hiding this comment

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

medium

For consistency with other accessor methods and to provide stronger compile-time guarantees, it's good practice to mark methods that do not throw exceptions as noexcept.

Suggested change
/// Returns the underlying object.
const std::tm& value() const { return tm_; }
const std::tm& value() const noexcept { return tm_; }

This commit adds `operator*` (const and non-const) to all reflect-cpp wrapper classes,
including `DefaultVal`, `Field`, `Validator`, `Description`, `Rename`, `Attribute`,
`Flatten`, `Hex`, `Oct`, `Binary`, `Generic`, `Timestamp`, and `internal::Skip`.
Additionally, it ensures that these classes have non-const `.get()`, `.value()`,
and `operator()()`, providing consistent access to the underlying value.
All these accessors are now marked as `noexcept` where appropriate.
Documentation has also been updated to reflect these changes.

Co-authored-by: liuzicheng1987 <19538706+liuzicheng1987@users.noreply.github.com>
@liuzicheng1987 liuzicheng1987 merged commit 9b57d01 into main Feb 8, 2026
340 of 349 checks passed
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