Skip to content

Commit 0246935

Browse files
committed
refactor: replace per-type operator==() and operator<=>() with a single generic template
Add a reflection-based operator==() and operator<=>() template pair that compare bases then members using the MRDOCS_DESCRIBE metadata. This removes almost all per-type overloads.
1 parent 72fba40 commit 0246935

106 files changed

Lines changed: 1639 additions & 1930 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/mrdocs/Metadata/DocComment/Block/AdmonitionBlock.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,6 @@ struct AdmonitionBlock final
5656
: admonish(admonish_)
5757
{}
5858

59-
/** Compare admonitions by kind, title, and contents.
60-
*/
61-
auto operator<=>(AdmonitionBlock const&) const = default;
62-
63-
/** Equality compares the admonition contents.
64-
*/
65-
bool operator==(AdmonitionBlock const&) const noexcept = default;
6659
};
6760

6861
MRDOCS_DESCRIBE_STRUCT(

include/mrdocs/Metadata/DocComment/Block/BlockBase.hpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@
2121
#include <mrdocs/Dom/LazyObject.hpp>
2222
#include <mrdocs/Metadata/DocComment/Block/BlockKind.hpp>
2323
#include <mrdocs/Metadata/DocComment/Inline.hpp>
24+
#include <mrdocs/Support/CompareReflectedType.hpp>
2425
#include <mrdocs/Support/Describe.hpp>
2526
#include <mrdocs/Support/MapReflectedType.hpp>
2627
#include <algorithm>
2728
#include <string>
2829

2930
namespace mrdocs::doc {
3031

32+
/// @copydoc mrdocs::operator<=>(T const&, T const&)
33+
using mrdocs::operator<=>;
34+
/// @copydoc mrdocs::operator==(T const&, T const&)
35+
using mrdocs::operator==;
36+
3137
/* Forward declarations
3238
*/
3339
#define INFO(Type) struct Type##Block;
@@ -49,16 +55,6 @@ struct MRDOCS_DECL Block
4955
*/
5056
virtual ~Block() = default;
5157

52-
/** Three-way comparison on the block contents.
53-
*/
54-
auto
55-
operator<=>(Block const& other) const = default;
56-
57-
/** Equality compares the block contents.
58-
*/
59-
bool
60-
operator==(Block const& other) const noexcept = default;
61-
6258
/** View this object as a `Block` reference.
6359
*/
6460
constexpr Block const& asBlock() const noexcept
@@ -146,10 +142,6 @@ struct BlockCommonBase : Block
146142
static constexpr bool is##Kind() noexcept { return K == BlockKind::Kind; }
147143
#include <mrdocs/Metadata/DocComment/Block/BlockNodes.inc>
148144

149-
/** Compare two blocks that share the same `kind_id`.
150-
*/
151-
auto operator<=>(BlockCommonBase const&) const = default;
152-
153145
MRDOCS_DESCRIBE_CLASS(BlockCommonBase, (Block), ())
154146

155147
protected:
@@ -228,15 +220,6 @@ struct MRDOCS_DECL BlockContainer
228220
return *this;
229221
}
230222

231-
/** Order containers lexicographically by their children.
232-
*/
233-
std::strong_ordering
234-
operator<=>(BlockContainer const&) const;
235-
236-
/** Equality compares the stored child blocks.
237-
*/
238-
bool
239-
operator==(BlockContainer const&) const = default;
240223
};
241224

242225
MRDOCS_DESCRIBE_STRUCT(

include/mrdocs/Metadata/DocComment/Block/BriefBlock.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ struct BriefBlock final
5858
*/
5959
using InlineContainer::operator=;
6060

61-
/** Compare briefs by inline content and provenance.
62-
*/
63-
auto operator<=>(BriefBlock const&) const = default;
6461
};
6562

6663
MRDOCS_DESCRIBE_STRUCT(

include/mrdocs/Metadata/DocComment/Block/CodeBlock.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ struct CodeBlock final
3535
/** Construct an empty code block.
3636
*/
3737
CodeBlock() noexcept = default;
38-
/** Compare code blocks by literal and info string.
39-
*/
40-
auto operator<=>(CodeBlock const&) const = default;
41-
/** Equality compares literal and info string.
42-
*/
43-
bool operator==(CodeBlock const&) const noexcept = default;
4438
};
4539

4640
MRDOCS_DESCRIBE_STRUCT(

include/mrdocs/Metadata/DocComment/Block/DefinitionListBlock.hpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,6 @@ struct DefinitionListBlock final
5656
*/
5757
std::vector<DefinitionListItem> items;
5858

59-
/** Order items and their definitions lexicographically.
60-
*/
61-
auto operator<=>(DefinitionListBlock const& other) const {
62-
if (auto const cmp = items.size() <=> other.items.size();
63-
!std::is_eq(cmp))
64-
{
65-
return cmp;
66-
}
67-
for (std::size_t i = 0; i < items.size(); ++i)
68-
{
69-
if (auto const cmp = items[i] <=> other.items[i];
70-
!std::is_eq(cmp))
71-
{
72-
return cmp;
73-
}
74-
}
75-
return std::strong_ordering::equal;
76-
}
77-
78-
/** Equality compares the contained items.
79-
*/
80-
bool
81-
operator==(DefinitionListBlock const&) const noexcept = default;
8259
};
8360

8461
MRDOCS_DESCRIBE_STRUCT(

include/mrdocs/Metadata/DocComment/Block/DefinitionListItem.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ struct DefinitionListItem final
2929
*/
3030
InlineContainer term;
3131

32-
/** Compare items by term and definition blocks.
33-
*/
34-
auto operator<=>(DefinitionListItem const&) const = default;
35-
36-
/** Equality compares term and definitions.
37-
*/
38-
bool operator==(DefinitionListItem const&) const noexcept = default;
3932
};
4033

4134
MRDOCS_DESCRIBE_STRUCT(

include/mrdocs/Metadata/DocComment/Block/FootnoteDefinitionBlock.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ struct FootnoteDefinitionBlock final
4242
/** Construct an empty footnote definition.
4343
*/
4444
FootnoteDefinitionBlock() noexcept = default;
45-
/** Compare definitions by label and block content.
46-
*/
47-
auto operator<=>(FootnoteDefinitionBlock const&) const = default;
48-
/** Equality compares label and block content.
49-
*/
50-
bool operator==(FootnoteDefinitionBlock const&) const noexcept = default;
5145
};
5246

5347
MRDOCS_DESCRIBE_STRUCT(

include/mrdocs/Metadata/DocComment/Block/HeadingBlock.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ struct HeadingBlock final
5050
*/
5151
using InlineContainer::InlineContainer;
5252

53-
/** Order headings by level and inline content.
54-
*/
55-
auto operator<=>(HeadingBlock const&) const = default;
56-
57-
/** Equality compares level and inline content.
58-
*/
59-
bool operator==(HeadingBlock const&) const noexcept = default;
6053
};
6154

6255
MRDOCS_DESCRIBE_STRUCT(

include/mrdocs/Metadata/DocComment/Block/ListBlock.hpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,29 +83,6 @@ struct ListBlock final
8383
*/
8484
ListKind listKind = ListKind::Unordered;
8585

86-
/** Order lists by item content and list style.
87-
*/
88-
auto operator<=>(ListBlock const& other) const {
89-
if (auto const cmp = items.size() <=> other.items.size();
90-
!std::is_eq(cmp))
91-
{
92-
return cmp;
93-
}
94-
for (std::size_t i = 0; i < items.size(); ++i)
95-
{
96-
if (auto const cmp = items[i] <=> other.items[i];
97-
!std::is_eq(cmp))
98-
{
99-
return cmp;
100-
}
101-
}
102-
return std::strong_ordering::equal;
103-
}
104-
105-
/** Equality compares the list style and items.
106-
*/
107-
bool
108-
operator==(ListBlock const&) const noexcept = default;
10986
};
11087

11188
MRDOCS_DESCRIBE_STRUCT(

include/mrdocs/Metadata/DocComment/Block/ListItem.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ namespace mrdocs::doc {
2525
struct ListItem final
2626
: BlockContainer
2727
{
28-
/** Order list items by their child blocks.
29-
*/
30-
auto operator<=>(ListItem const&) const = default;
31-
32-
/** Equality compares contained blocks.
33-
*/
34-
bool operator==(ListItem const&) const noexcept = default;
3528
};
3629

3730
MRDOCS_DESCRIBE_STRUCT(

0 commit comments

Comments
 (0)