From df7248039553b3ebd338380c3ef0428b0e046e79 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 14 Aug 2020 09:38:45 -0400 Subject: common: Make use of [[nodiscard]] where applicable Now that clang-format makes [[nodiscard]] attributes format sensibly, we can apply them to several functions within the common library to allow the compiler to complain about any misuses of the functions. --- src/common/math_util.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/common/math_util.h') diff --git a/src/common/math_util.h b/src/common/math_util.h index abca3177c..cc35c90ee 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h @@ -23,7 +23,7 @@ struct Rectangle { constexpr Rectangle(T left, T top, T right, T bottom) : left(left), top(top), right(right), bottom(bottom) {} - T GetWidth() const { + [[nodiscard]] T GetWidth() const { if constexpr (std::is_floating_point_v) { return std::abs(right - left); } else { @@ -31,7 +31,7 @@ struct Rectangle { } } - T GetHeight() const { + [[nodiscard]] T GetHeight() const { if constexpr (std::is_floating_point_v) { return std::abs(bottom - top); } else { @@ -39,15 +39,15 @@ struct Rectangle { } } - Rectangle TranslateX(const T x) const { + [[nodiscard]] Rectangle TranslateX(const T x) const { return Rectangle{left + x, top, right + x, bottom}; } - Rectangle TranslateY(const T y) const { + [[nodiscard]] Rectangle TranslateY(const T y) const { return Rectangle{left, top + y, right, bottom + y}; } - Rectangle Scale(const float s) const { + [[nodiscard]] Rectangle Scale(const float s) const { return Rectangle{left, top, static_cast(left + GetWidth() * s), static_cast(top + GetHeight() * s)}; } -- cgit v1.2.3