From a1d32e3388f5a1a3b09ed6581a1f215f7497f75a Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 14 Jul 2016 19:40:39 +0300 Subject: [PATCH] constexpr all operators --- include/mapbox/geometry/box.hpp | 6 ++-- include/mapbox/geometry/feature.hpp | 8 ++--- include/mapbox/geometry/point.hpp | 6 ++-- include/mapbox/geometry/point_arithmetic.hpp | 32 ++++++++++---------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/mapbox/geometry/box.hpp b/include/mapbox/geometry/box.hpp index 3016a5f..bf81b70 100644 --- a/include/mapbox/geometry/box.hpp +++ b/include/mapbox/geometry/box.hpp @@ -10,7 +10,7 @@ struct box { using point_type = point; - box(point_type const& min_, point_type const& max_) + constexpr box(point_type const& min_, point_type const& max_) : min(min_), max(max_) {} @@ -19,13 +19,13 @@ struct box }; template -bool operator==(box const& lhs, box const& rhs) +constexpr bool operator==(box const& lhs, box const& rhs) { return lhs.min == rhs.min && lhs.max == rhs.max; } template -bool operator!=(box const& lhs, box const& rhs) +constexpr bool operator!=(box const& lhs, box const& rhs) { return lhs.min != rhs.min || lhs.max != rhs.max; } diff --git a/include/mapbox/geometry/feature.hpp b/include/mapbox/geometry/feature.hpp index 15dfa2a..3bdd484 100644 --- a/include/mapbox/geometry/feature.hpp +++ b/include/mapbox/geometry/feature.hpp @@ -21,8 +21,8 @@ struct null_value_t constexpr null_value_t(std::nullptr_t) {} }; -inline bool operator==(const null_value_t&, const null_value_t&) { return true; } -inline bool operator!=(const null_value_t&, const null_value_t&) { return false; } +constexpr bool operator==(const null_value_t&, const null_value_t&) { return true; } +constexpr bool operator!=(const null_value_t&, const null_value_t&) { return false; } constexpr null_value_t null_value = null_value_t(); @@ -57,13 +57,13 @@ struct feature }; template -bool operator==(feature const& lhs, feature const& rhs) +constexpr bool operator==(feature const& lhs, feature const& rhs) { return lhs.id == rhs.id && lhs.geometry == rhs.geometry && lhs.properties == rhs.properties; } template -bool operator!=(feature const& lhs, feature const& rhs) +constexpr bool operator!=(feature const& lhs, feature const& rhs) { return !(lhs == rhs); } diff --git a/include/mapbox/geometry/point.hpp b/include/mapbox/geometry/point.hpp index 847e3b0..0cba499 100644 --- a/include/mapbox/geometry/point.hpp +++ b/include/mapbox/geometry/point.hpp @@ -20,15 +20,15 @@ struct point }; template -bool operator==(point const& lhs, point const& rhs) +constexpr bool operator==(point const& lhs, point const& rhs) { return lhs.x == rhs.x && lhs.y == rhs.y; } template -bool operator!=(point const& lhs, point const& rhs) +constexpr bool operator!=(point const& lhs, point const& rhs) { - return lhs.x != rhs.x || lhs.y != rhs.y; + return !(lhs == rhs); } } // namespace geometry diff --git a/include/mapbox/geometry/point_arithmetic.hpp b/include/mapbox/geometry/point_arithmetic.hpp index 0c4c632..3940e5b 100644 --- a/include/mapbox/geometry/point_arithmetic.hpp +++ b/include/mapbox/geometry/point_arithmetic.hpp @@ -4,55 +4,55 @@ namespace mapbox { namespace geometry { template -point operator+(point const& lhs, point const& rhs) +constexpr point operator+(point const& lhs, point const& rhs) { return point(lhs.x + rhs.x, lhs.y + rhs.y); } template -point operator+(point const& lhs, T const& rhs) +constexpr point operator+(point const& lhs, T const& rhs) { return point(lhs.x + rhs, lhs.y + rhs); } template -point operator-(point const& lhs, point const& rhs) +constexpr point operator-(point const& lhs, point const& rhs) { return point(lhs.x - rhs.x, lhs.y - rhs.y); } template -point operator-(point const& lhs, T const& rhs) +constexpr point operator-(point const& lhs, T const& rhs) { return point(lhs.x - rhs, lhs.y - rhs); } template -point operator*(point const& lhs, point const& rhs) +constexpr point operator*(point const& lhs, point const& rhs) { return point(lhs.x * rhs.x, lhs.y * rhs.y); } template -point operator*(point const& lhs, T const& rhs) +constexpr point operator*(point const& lhs, T const& rhs) { return point(lhs.x * rhs, lhs.y * rhs); } template -point operator/(point const& lhs, point const& rhs) +constexpr point operator/(point const& lhs, point const& rhs) { return point(lhs.x / rhs.x, lhs.y / rhs.y); } template -point operator/(point const& lhs, T const& rhs) +constexpr point operator/(point const& lhs, T const& rhs) { return point(lhs.x / rhs, lhs.y / rhs); } template -point& operator+=(point& lhs, point const& rhs) +constexpr point& operator+=(point& lhs, point const& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; @@ -60,7 +60,7 @@ point& operator+=(point& lhs, point const& rhs) } template -point& operator+=(point& lhs, T const& rhs) +constexpr point& operator+=(point& lhs, T const& rhs) { lhs.x += rhs; lhs.y += rhs; @@ -68,7 +68,7 @@ point& operator+=(point& lhs, T const& rhs) } template -point& operator-=(point& lhs, point const& rhs) +constexpr point& operator-=(point& lhs, point const& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; @@ -76,7 +76,7 @@ point& operator-=(point& lhs, point const& rhs) } template -point& operator-=(point& lhs, T const& rhs) +constexpr point& operator-=(point& lhs, T const& rhs) { lhs.x -= rhs; lhs.y -= rhs; @@ -84,7 +84,7 @@ point& operator-=(point& lhs, T const& rhs) } template -point& operator*=(point& lhs, point const& rhs) +constexpr point& operator*=(point& lhs, point const& rhs) { lhs.x *= rhs.x; lhs.y *= rhs.y; @@ -92,7 +92,7 @@ point& operator*=(point& lhs, point const& rhs) } template -point& operator*=(point& lhs, T const& rhs) +constexpr point& operator*=(point& lhs, T const& rhs) { lhs.x *= rhs; lhs.y *= rhs; @@ -100,7 +100,7 @@ point& operator*=(point& lhs, T const& rhs) } template -point& operator/=(point& lhs, point const& rhs) +constexpr point& operator/=(point& lhs, point const& rhs) { lhs.x /= rhs.x; lhs.y /= rhs.y; @@ -108,7 +108,7 @@ point& operator/=(point& lhs, point const& rhs) } template -point& operator/=(point& lhs, T const& rhs) +constexpr point& operator/=(point& lhs, T const& rhs) { lhs.x /= rhs; lhs.y /= rhs;