Skip to content

refactor: replace per-type operator==() and operator<=>() with a single generic template for doc types#1177

Open
gennaroprota wants to merge 1 commit intocppalliance:developfrom
gennaroprota:refactor/leverage_reflection_for_the_comparison_operators
Open

refactor: replace per-type operator==() and operator<=>() with a single generic template for doc types#1177
gennaroprota wants to merge 1 commit intocppalliance:developfrom
gennaroprota:refactor/leverage_reflection_for_the_comparison_operators

Conversation

@gennaroprota
Copy link
Copy Markdown
Collaborator

@gennaroprota gennaroprota commented Apr 10, 2026

Add a reflection-based operator<=>() and operator==() template pair that compare bases then members using the MRDOCS_DESCRIBE metadata. This removes ~40 per-type = default and hand-written operator<=>() implementations from all DocComment Block and Inline types.

The templates live in mrdocs::describe_ops rather than mrdocs to work around an MSVC bug: adding any constrained template to namespace mrdocs causes the unrelated merge() template to fail resolving recursive calls from within lambdas, even though both templates are well-formed C++ (confirmed with clang-cl 21.1.5). As a consequence, the operator<=>() overloads in namespace mrdocs (Symbol, Type, Name, Template types, etc.) cannot be replaced yet — the generic template is not reachable by ADL from that namespace, and importing it via using-declarations triggers the bug.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 10, 2026

🚧 Danger.js checks for MrDocs are experimental; expect some rough edges while we tune the rules.

⚠️ Warnings

Warning

Add a brief note about how this change was tested (or why tests are not needed).

🧾 Changes by Scope

Scope Lines Δ% Lines Δ Lines + Lines - Files Δ Files + Files ~ Files ↔ Files -
🛠️ Source 100% 450 100 350 45 1 44 - -
Total 100% 450 100 350 45 1 44 - -

Legend: Files + (added), Files ~ (modified), Files ↔ (renamed), Files - (removed)

🔝 Top Files

  • include/mrdocs/Support/CompareReflectedType.hpp (Source): 87 lines Δ (+87 / -0)
  • include/mrdocs/Metadata/DocComment/Inline/InlineBase.hpp (Source): 32 lines Δ (+6 / -26)
  • include/mrdocs/Metadata/DocComment/Block/BlockBase.hpp (Source): 29 lines Δ (+6 / -23)

Generated by 🚫 dangerJS against 2f73a34

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2026

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 78.64%. Comparing base (4ae305b) to head (2f73a34).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
include/mrdocs/Support/CompareReflectedType.hpp 95.45% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1177      +/-   ##
===========================================
+ Coverage    78.46%   78.64%   +0.17%     
===========================================
  Files          336      311      -25     
  Lines        32219    32161      -58     
  Branches      6480     6473       -7     
===========================================
+ Hits         25282    25292      +10     
+ Misses        4567     4498      -69     
- Partials      2370     2371       +1     
Flag Coverage Δ
bootstrap 81.89% <ø> (ø)
cpp 78.30% <95.45%> (+0.18%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cppalliance-bot
Copy link
Copy Markdown

cppalliance-bot commented Apr 10, 2026

An automated preview of the documentation is available at https://1177.mrdocs.prtest2.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-04-10 14:34:06 UTC

…le generic template for doc types

Add a reflection-based operator<=>() and operator==() template pair that
compare bases then members using the MRDOCS_DESCRIBE metadata. This
removes ~40 per-type = default and hand-written operator<=>()
implementations from all DocComment Block and Inline types.

The templates live in mrdocs::describe_ops rather than mrdocs to work
around an MSVC bug: adding any constrained template to namespace mrdocs
causes the unrelated merge() template to fail resolving recursive calls
from within lambdas, even though both templates are well-formed C++
(confirmed with clang-cl 21.1.5). As a consequence, the operator<=>()
overloads in namespace mrdocs (Symbol, Type, Name, Template types, etc.)
cannot be replaced yet — the generic template is not reachable by ADL
from that namespace, and importing it via using-declarations triggers
the bug.
@gennaroprota gennaroprota force-pushed the refactor/leverage_reflection_for_the_comparison_operators branch from 6ad7c2d to 2f73a34 Compare April 10, 2026 14:27
Copy link
Copy Markdown
Collaborator

@alandefreitas alandefreitas left a comment

Choose a reason for hiding this comment

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

Looks amazing to me!

@gennaroprota
Copy link
Copy Markdown
Collaborator Author

Thanks. Unfortunately, that MSVC bug doesn't allow removing more overloads.

@alandefreitas
Copy link
Copy Markdown
Collaborator

As a consequence, the operator<=>() overloads in namespace mrdocs (Symbol, Type, Name, Template types, etc.) cannot be replaced yet

I'm a little confused by the limitation. So the operator<=>() overloads in namespace mrdocs can't be replaced, but the ones in mrdocs::doc can? Or both can't? And if both can't, what can? I think from the description alone I couldn't mentally visualize all the instances of the problem described.

@gennaroprota
Copy link
Copy Markdown
Collaborator Author

gennaroprota commented Apr 10, 2026 via email

@alandefreitas
Copy link
Copy Markdown
Collaborator

alandefreitas commented Apr 10, 2026

The overloads in mrdocs can't. The ones in mrdocs::doc can.

Oh... I really don't understand this bug then. :)

I'll study it a little better.

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.

3 participants