summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-02-02 23:24:32 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-02-03 10:02:25 -0800
commit235210c64864e1bbccceb2a551a521ce72cbdadd (patch)
tree26ab9bc847a06b364c39be79466c166a77bc9374 /include
parent9beb6629b68f2c07ff3f778d9bf4acfbcb3b6598 (diff)
downloadqtlocation-mapboxgl-235210c64864e1bbccceb2a551a521ce72cbdadd.tar.gz
[core] Make bool conversions explicit
Implicit bool conversions are bad; they'll be used e.g. for a == b and a != b if those operators are not defined. This was happening at https://github.com/mapbox/mapbox-gl-native/blob/032c8fba3c8e3c122dd399b5c9341d92ad9d286f/src/mbgl/map/transform.cpp#L132-L132, for example.
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/util/geo.hpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp
index 0f6a049962..99b5743877 100644
--- a/include/mbgl/util/geo.hpp
+++ b/include/mbgl/util/geo.hpp
@@ -19,7 +19,7 @@ public:
LatLng(double lat = 0, double lon = 0)
: latitude(lat), longitude(lon) {}
- operator bool() const {
+ explicit operator bool() const {
return !(std::isnan(latitude) || std::isnan(longitude));
}
@@ -29,6 +29,14 @@ public:
PrecisionPoint project() const;
};
+inline bool operator==(const LatLng& a, const LatLng& b) {
+ return a.latitude == b.latitude && a.longitude == b.longitude;
+}
+
+inline bool operator!=(const LatLng& a, const LatLng& b) {
+ return !(a == b);
+}
+
class ProjectedMeters {
public:
double northing = 0;
@@ -37,7 +45,7 @@ public:
ProjectedMeters(double n = 0, double e = 0)
: northing(n), easting(e) {}
- operator bool() const {
+ explicit operator bool() const {
return !(std::isnan(northing) || std::isnan(easting));
}
};
@@ -133,7 +141,7 @@ public:
MetersBounds(const ProjectedMeters& sw_, const ProjectedMeters& ne_)
: sw(sw_), ne(ne_) {}
- operator bool() const {
+ explicit operator bool() const {
return sw && ne;
}
};
@@ -159,7 +167,7 @@ public:
EdgeInsets(const double t, const double l, const double b, const double r)
: top(t), left(l), bottom(b), right(r) {}
- operator bool() const {
+ explicit operator bool() const {
return top || left || bottom || right;
}