Skip to content

Add MATLAB support for std::optional - #199

Merged
ProfFan merged 1 commit into
masterfrom
fix/matlab-optional-caster
Aug 20, 2026
Merged

Add MATLAB support for std::optional#199
ProfFan merged 1 commit into
masterfrom
fix/matlab-optional-caster

Conversation

@ProfFan

@ProfFan ProfFan commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • map std::nullopt to MATLAB [], and MATLAB [] back to std::nullopt
  • recursively use the contained type's normal MATLAB conversion for engaged optionals
  • preserve shared ownership for wrapped objects by copying optional class values into proxy-owned shared_ptrs
  • represent std::optional<std::pair<T, U>> with the wrapper's existing two-output convention, returning [] for both outputs when disengaged
  • document the MATLAB optional contract and add generator coverage for values, objects, arguments, properties, and pairs

Motivation

The existing generator dereferenced optional results but still instantiated a shared_ptr<std::optional<T>>. That produced invalid generated C++ and provided no representation for a disengaged optional.

Validation

  • python3 -m unittest discover -s tests — 112 tests passed
  • generated the complete GTSAM MATLAB wrapper, including 406 optional conversion sites
  • compiled the full 6.6 MB generated wrapper with Octave 11.3 MEX headers
  • passed Octave runtime smoke tests for:
    • disengaged and engaged std::optional<Pose3> returns
    • MATLAB [] passed to an optional argument in ISAM2.update
    • optional vector and matrix values
    • std::optional<std::pair<Vector, Matrix>> outputs

@ProfFan
ProfFan merged commit 1dd055d into master Aug 20, 2026
8 checks passed
@ProfFan
ProfFan deleted the fix/matlab-optional-caster branch August 20, 2026 04:30
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.

2 participants