Skip to content

refactor(cpp): adopt deducing-this pattern - #295

Open
robertodr wants to merge 4 commits into
mainfrom
refactor-deducing-this
Open

refactor(cpp): adopt deducing-this pattern#295
robertodr wants to merge 4 commits into
mainfrom
refactor-deducing-this

Conversation

@robertodr

Copy link
Copy Markdown
Member

Summary

🤖 AI text below 🤖

This pull request introduces a significant refactor to the C++ codebase, adopting C++23 "deducing this" member functions to unify const and non-const accessors, reduce code duplication, and improve maintainability. The changes affect several core classes, including MPGraph, MonomialPropagator, Bitset, and related test files, and also introduce a new LayerWindow mixin to share accessor logic. Additionally, the documentation and test assertions are updated to reflect and verify the new idioms.

Adoption of C++23 "deducing this" idiom and accessor refactoring:

Documentation and style guide updates:

Test and assertion improvements:

General codebase improvements:

These changes modernize the codebase, reduce maintenance burden, and ensure safer and clearer accessor patterns throughout the project.

Checklist

  • Tests added or updated to cover the changes
  • Documentation updated (docstrings, docs/, CONTRIBUTING.md) if needed
  • CHANGELOG / release notes updated if applicable

AI/LLM disclosure

  • I did not use LLM tooling, or used it only privately for ideation
  • I used the following tool to help write this PR description:
  • I used the following tool to generate or modify code: ClaudeCode: claude-opus-5

Important

By opening this PR I confirm that I have read CONTRIBUTING.md and I agree to the terms of the Contributor License Agreement.

Warning

If you're contributing on behalf of your employer, contact cla@algorithmiq.fi to arrange a Corporate CLA.

Ubuntu added 2 commits August 26, 2026 19:00
…educing this

MPGraph carried three const/non-const overload pairs whose bodies were identical
(active_begin_iterator, active_end_iterator, get_layer), and MPGraphView carried a
fourth copy of get_layer_traversal. An explicit object parameter deduces the
const-ness instead of declaring it, which also retires the LayerIterator/
ConstLayerIterator alias pair, and a LayerWindow mixin gives both the graph and its
views one get_layer_traversal derived from whatever get_layer they expose --
deducing this rather than CRTP, so neither class names itself as a template argument.

MonomialPropagator::mp_op()/indexing() duplicated their require_single_partition_
guard across the two overloads, so the guard string could drift. indexing() reaches
its result through a unique_ptr, whose operator* yields a mutable referent whatever
the owner's const-ness, so it needs std::forward_like to stay const-correct; new
static_asserts pin that down, since nothing else observed it.

Assisted-by: ClaudeCode:claude-opus-5
Bitset::data() and PartitionGroup::partition() were const/non-const overload pairs
with one body each; partition() dereferences a unique_ptr, so it needs
std::forward_like to keep the group's const-ness.

The bitwise operators keep their hidden-friend form on purpose. Taking the object
parameter by value would make it the working copy and shorten each to one line, but a
by-value object parameter is a stack array: NRVO no longer applies, and under
-fstack-protector-strong (the platform default) GCC 15 grows operator^ from four
instructions to twelve, adding a frame and a canary check to the library's hottest
primitive. Recorded in a comment there and as a rule in AGENTS.md, so the next reader
does not re-derive it.

Assisted-by: ClaudeCode:claude-opus-5
@github-actions github-actions Bot added documentation Improvements or additions to documentation cpp labels Aug 26, 2026
@github-actions

Copy link
Copy Markdown

Docs preview: https://pr-295.monoprop-docs.pages.dev

@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.70%. Comparing base (665508e) to head (76b7c7b).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #295   +/-   ##
=======================================
  Coverage   97.70%   97.70%           
=======================================
  Files          14       14           
  Lines         742      742           
  Branches       98       98           
=======================================
  Hits          725      725           
  Misses         12       12           
  Partials        5        5           
Flag Coverage Δ
cpp 97.70% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cpp documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant