Skip to content

Commit

Permalink
constexpr all operators
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Sep 28, 2016
1 parent 03778c6 commit a1d32e3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions include/mapbox/geometry/box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct box
{
using point_type = point<T>;

box(point_type const& min_, point_type const& max_)
constexpr box(point_type const& min_, point_type const& max_)
: min(min_), max(max_)
{}

Expand All @@ -19,13 +19,13 @@ struct box
};

template <typename T>
bool operator==(box<T> const& lhs, box<T> const& rhs)
constexpr bool operator==(box<T> const& lhs, box<T> const& rhs)
{
return lhs.min == rhs.min && lhs.max == rhs.max;
}

template <typename T>
bool operator!=(box<T> const& lhs, box<T> const& rhs)
constexpr bool operator!=(box<T> const& lhs, box<T> const& rhs)
{
return lhs.min != rhs.min || lhs.max != rhs.max;
}
Expand Down
8 changes: 4 additions & 4 deletions include/mapbox/geometry/feature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -57,13 +57,13 @@ struct feature
};

template <class T>
bool operator==(feature<T> const& lhs, feature<T> const& rhs)
constexpr bool operator==(feature<T> const& lhs, feature<T> const& rhs)
{
return lhs.id == rhs.id && lhs.geometry == rhs.geometry && lhs.properties == rhs.properties;
}

template <class T>
bool operator!=(feature<T> const& lhs, feature<T> const& rhs)
constexpr bool operator!=(feature<T> const& lhs, feature<T> const& rhs)
{
return !(lhs == rhs);
}
Expand Down
6 changes: 3 additions & 3 deletions include/mapbox/geometry/point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ struct point
};

template <typename T>
bool operator==(point<T> const& lhs, point<T> const& rhs)
constexpr bool operator==(point<T> const& lhs, point<T> const& rhs)
{
return lhs.x == rhs.x && lhs.y == rhs.y;
}

template <typename T>
bool operator!=(point<T> const& lhs, point<T> const& rhs)
constexpr bool operator!=(point<T> const& lhs, point<T> const& rhs)
{
return lhs.x != rhs.x || lhs.y != rhs.y;
return !(lhs == rhs);
}

} // namespace geometry
Expand Down
32 changes: 16 additions & 16 deletions include/mapbox/geometry/point_arithmetic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,111 +4,111 @@ namespace mapbox {
namespace geometry {

template <typename T>
point<T> operator+(point<T> const& lhs, point<T> const& rhs)
constexpr point<T> operator+(point<T> const& lhs, point<T> const& rhs)
{
return point<T>(lhs.x + rhs.x, lhs.y + rhs.y);
}

template <typename T>
point<T> operator+(point<T> const& lhs, T const& rhs)
constexpr point<T> operator+(point<T> const& lhs, T const& rhs)
{
return point<T>(lhs.x + rhs, lhs.y + rhs);
}

template <typename T>
point<T> operator-(point<T> const& lhs, point<T> const& rhs)
constexpr point<T> operator-(point<T> const& lhs, point<T> const& rhs)
{
return point<T>(lhs.x - rhs.x, lhs.y - rhs.y);
}

template <typename T>
point<T> operator-(point<T> const& lhs, T const& rhs)
constexpr point<T> operator-(point<T> const& lhs, T const& rhs)
{
return point<T>(lhs.x - rhs, lhs.y - rhs);
}

template <typename T>
point<T> operator*(point<T> const& lhs, point<T> const& rhs)
constexpr point<T> operator*(point<T> const& lhs, point<T> const& rhs)
{
return point<T>(lhs.x * rhs.x, lhs.y * rhs.y);
}

template <typename T>
point<T> operator*(point<T> const& lhs, T const& rhs)
constexpr point<T> operator*(point<T> const& lhs, T const& rhs)
{
return point<T>(lhs.x * rhs, lhs.y * rhs);
}

template <typename T>
point<T> operator/(point<T> const& lhs, point<T> const& rhs)
constexpr point<T> operator/(point<T> const& lhs, point<T> const& rhs)
{
return point<T>(lhs.x / rhs.x, lhs.y / rhs.y);
}

template <typename T>
point<T> operator/(point<T> const& lhs, T const& rhs)
constexpr point<T> operator/(point<T> const& lhs, T const& rhs)
{
return point<T>(lhs.x / rhs, lhs.y / rhs);
}

template <typename T>
point<T>& operator+=(point<T>& lhs, point<T> const& rhs)
constexpr point<T>& operator+=(point<T>& lhs, point<T> const& rhs)
{
lhs.x += rhs.x;
lhs.y += rhs.y;
return lhs;
}

template <typename T>
point<T>& operator+=(point<T>& lhs, T const& rhs)
constexpr point<T>& operator+=(point<T>& lhs, T const& rhs)
{
lhs.x += rhs;
lhs.y += rhs;
return lhs;
}

template <typename T>
point<T>& operator-=(point<T>& lhs, point<T> const& rhs)
constexpr point<T>& operator-=(point<T>& lhs, point<T> const& rhs)
{
lhs.x -= rhs.x;
lhs.y -= rhs.y;
return lhs;
}

template <typename T>
point<T>& operator-=(point<T>& lhs, T const& rhs)
constexpr point<T>& operator-=(point<T>& lhs, T const& rhs)
{
lhs.x -= rhs;
lhs.y -= rhs;
return lhs;
}

template <typename T>
point<T>& operator*=(point<T>& lhs, point<T> const& rhs)
constexpr point<T>& operator*=(point<T>& lhs, point<T> const& rhs)
{
lhs.x *= rhs.x;
lhs.y *= rhs.y;
return lhs;
}

template <typename T>
point<T>& operator*=(point<T>& lhs, T const& rhs)
constexpr point<T>& operator*=(point<T>& lhs, T const& rhs)
{
lhs.x *= rhs;
lhs.y *= rhs;
return lhs;
}

template <typename T>
point<T>& operator/=(point<T>& lhs, point<T> const& rhs)
constexpr point<T>& operator/=(point<T>& lhs, point<T> const& rhs)
{
lhs.x /= rhs.x;
lhs.y /= rhs.y;
return lhs;
}

template <typename T>
point<T>& operator/=(point<T>& lhs, T const& rhs)
constexpr point<T>& operator/=(point<T>& lhs, T const& rhs)
{
lhs.x /= rhs;
lhs.y /= rhs;
Expand Down

0 comments on commit a1d32e3

Please sign in to comment.