Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add equality operators to CSS data types #48989

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace facebook::react {
*/
struct CSSAngle {
float degrees{};

constexpr bool operator==(const CSSAngle& rhs) const = default;
};

template <>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ struct CSSColor {
uint8_t g{};
uint8_t b{};
uint8_t a{};

constexpr bool operator==(const CSSColor& rhs) const = default;

static constexpr CSSColor black() {
return {0, 0, 0, 255};
}
};

template <>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ concept CSSValidDataTypeParser = CSSFunctionBlockSink<T, ReturnT> ||
CSSSimplePreservedTokenSink<T, ReturnT>;

/**
* Concrete representation for a CSS data type, or keywords
* Concrete representation for a CSS data type
*/
template <typename T>
concept CSSDataType =
CSSValidDataTypeParser<CSSDataTypeParser<T>, std::optional<T>>;
CSSValidDataTypeParser<CSSDataTypeParser<T>, std::optional<T>> &&
std::equality_comparable<T>;

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace facebook::react {
struct CSSLength {
float value{};
CSSLengthUnit unit{CSSLengthUnit::Px};

constexpr bool operator==(const CSSLength& rhs) const = default;
};

template <>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace facebook::react {
*/
struct CSSNumber {
float value{};

constexpr bool operator==(const CSSNumber& rhs) const = default;
};

template <>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace facebook::react {
*/
struct CSSPercentage {
float value{};

constexpr bool operator==(const CSSPercentage& rhs) const = default;
};

template <>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ struct CSSRatio {
float numerator{};
float denominator{};

constexpr bool operator==(const CSSRatio& rhs) const = default;

constexpr bool isDegenerate() const {
// If either number in the <ratio> is 0 or infinite, it represents a
// degenerate ratio (and, generally, won’t do anything).
Expand Down
Loading