Skip to content

Commit c480a5a

Browse files
Merge pull request #7 from mcpplibs/pr-6
fix: CI Test
2 parents b065474 + 81df870 commit c480a5a

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

examples/ex06_custom_underlying.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,31 @@ struct NonNegativeInt {
3232
struct TaggedLhs {
3333
int value;
3434

35+
friend constexpr auto operator+(TaggedLhs lhs, TaggedLhs rhs) noexcept
36+
-> TaggedLhs {
37+
return TaggedLhs{lhs.value + rhs.value};
38+
}
39+
40+
friend constexpr auto operator-(TaggedLhs lhs, TaggedLhs rhs) noexcept
41+
-> TaggedLhs {
42+
return TaggedLhs{lhs.value - rhs.value};
43+
}
44+
45+
friend constexpr auto operator*(TaggedLhs lhs, TaggedLhs rhs) noexcept
46+
-> TaggedLhs {
47+
return TaggedLhs{lhs.value * rhs.value};
48+
}
49+
50+
friend constexpr auto operator/(TaggedLhs lhs, TaggedLhs rhs) noexcept
51+
-> TaggedLhs {
52+
return TaggedLhs{lhs.value / rhs.value};
53+
}
54+
55+
friend constexpr auto operator==(TaggedLhs lhs, TaggedLhs rhs) noexcept
56+
-> bool {
57+
return lhs.value == rhs.value;
58+
}
59+
3560
constexpr explicit operator long long() const noexcept {
3661
return static_cast<long long>(value);
3762
}
@@ -40,6 +65,31 @@ struct TaggedLhs {
4065
struct TaggedRhs {
4166
int value;
4267

68+
friend constexpr auto operator+(TaggedRhs lhs, TaggedRhs rhs) noexcept
69+
-> TaggedRhs {
70+
return TaggedRhs{lhs.value + rhs.value};
71+
}
72+
73+
friend constexpr auto operator-(TaggedRhs lhs, TaggedRhs rhs) noexcept
74+
-> TaggedRhs {
75+
return TaggedRhs{lhs.value - rhs.value};
76+
}
77+
78+
friend constexpr auto operator*(TaggedRhs lhs, TaggedRhs rhs) noexcept
79+
-> TaggedRhs {
80+
return TaggedRhs{lhs.value * rhs.value};
81+
}
82+
83+
friend constexpr auto operator/(TaggedRhs lhs, TaggedRhs rhs) noexcept
84+
-> TaggedRhs {
85+
return TaggedRhs{lhs.value / rhs.value};
86+
}
87+
88+
friend constexpr auto operator==(TaggedRhs lhs, TaggedRhs rhs) noexcept
89+
-> bool {
90+
return lhs.value == rhs.value;
91+
}
92+
4393
constexpr explicit operator long long() const noexcept {
4494
return static_cast<long long>(value);
4595
}
@@ -48,6 +98,11 @@ struct TaggedRhs {
4898
struct TaggedCommonRep {
4999
long long value;
50100

101+
constexpr TaggedCommonRep() noexcept = default;
102+
constexpr explicit TaggedCommonRep(long long v) noexcept : value(v) {}
103+
constexpr explicit TaggedCommonRep(TaggedLhs v) noexcept : value(v.value) {}
104+
constexpr explicit TaggedCommonRep(TaggedRhs v) noexcept : value(v.value) {}
105+
51106
friend constexpr auto operator+(TaggedCommonRep lhs,
52107
TaggedCommonRep rhs) noexcept
53108
-> TaggedCommonRep {
@@ -156,6 +211,24 @@ template <> struct mcpplibs::primitives::underlying::traits<TaggedRhs> {
156211
static constexpr auto is_valid_rep(rep_type) noexcept -> bool { return true; }
157212
};
158213

214+
template <> struct mcpplibs::primitives::underlying::traits<TaggedCommonRep> {
215+
using value_type = TaggedCommonRep;
216+
using rep_type = TaggedCommonRep;
217+
218+
static constexpr bool enabled = true;
219+
static constexpr auto kind = category::integer;
220+
221+
static constexpr auto to_rep(value_type value) noexcept -> rep_type {
222+
return value;
223+
}
224+
225+
static constexpr auto from_rep(rep_type value) noexcept -> value_type {
226+
return value;
227+
}
228+
229+
static constexpr auto is_valid_rep(rep_type) noexcept -> bool { return true; }
230+
};
231+
159232
template <>
160233
struct mcpplibs::primitives::underlying::common_rep_traits<TaggedLhs,
161234
TaggedRhs> {

0 commit comments

Comments
 (0)