Skip to content

Commit 3d38eb5

Browse files
authored
Merge pull request #18 from 4ms/constexpr-ops
2 parents 962997c + de15b05 commit 3d38eb5

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

util/colors.hh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,14 @@ struct Color {
2727
uint8_t r, g, b;
2828
};
2929

30+
constexpr Color() = default;
31+
3032
explicit constexpr Color(uint8_t r, uint8_t g, uint8_t b)
3133
: r_(r)
3234
, g_(g)
3335
, b_(b) {
3436
}
3537

36-
constexpr Color()
37-
: r_(0)
38-
, g_(0)
39-
, b_(0) {
40-
}
41-
4238
constexpr Color(uint16_t rgb565)
4339
: r_((rgb565 & 0xf800) >> 8)
4440
, g_((rgb565 & 0x07e0) >> 3)
@@ -55,15 +51,15 @@ struct Color {
5551
return b_;
5652
}
5753

58-
const Color operator+(Color const that) const {
54+
constexpr Color operator+(Color const that) const {
5955
return Color(builtin_add_u8(r_, that.r_), builtin_add_u8(g_, that.g_), builtin_add_u8(b_, that.b_));
6056
}
6157

62-
const Color operator*(float phase) const {
58+
constexpr Color operator*(float phase) const {
6359
return Color{0, 0, 0}.blend(*this, phase);
6460
}
6561

66-
bool operator==(Color const &other) const {
62+
constexpr bool operator==(Color const &other) const {
6763
return (r_ == other.r_ && g_ == other.g_ && b_ == other.b_);
6864
}
6965

@@ -140,7 +136,9 @@ struct Color {
140136
}
141137

142138
private:
143-
uint8_t r_, g_, b_;
139+
uint8_t r_{};
140+
uint8_t g_{};
141+
uint8_t b_{};
144142
};
145143

146144
struct Colors {

0 commit comments

Comments
 (0)