diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-10-28 14:55:07 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-10-28 17:10:45 -0700 |
commit | a4c82b8a3b5e48f3bbccf32be80d45ca78d51515 (patch) | |
tree | dc5576c815a49fd310e6c599f87eac64d3f99e7d /src/mbgl/text/glyph.hpp | |
parent | ee3235708f5422c2737c41fca948c67ace598f4b (diff) | |
download | qtlocation-mapboxgl-a4c82b8a3b5e48f3bbccf32be80d45ca78d51515.tar.gz |
[core] operator bool() must always be explicit
Otherwise, it can participate in unexpected conversions. Case in point: GlyphSet::insert was comparing the result of GlyphMetrics::operator bool() where it wanted to use operator==.
Diffstat (limited to 'src/mbgl/text/glyph.hpp')
-rw-r--r-- | src/mbgl/text/glyph.hpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/mbgl/text/glyph.hpp b/src/mbgl/text/glyph.hpp index 975dc4ad23..a333f68ff4 100644 --- a/src/mbgl/text/glyph.hpp +++ b/src/mbgl/text/glyph.hpp @@ -14,7 +14,7 @@ namespace mbgl { GlyphRange getGlyphRange(char32_t glyph); struct GlyphMetrics { - operator bool() const { + explicit operator bool() const { return !(width == 0 && height == 0 && advance == 0); } @@ -27,12 +27,20 @@ struct GlyphMetrics { }; +inline bool operator==(const GlyphMetrics& lhs, const GlyphMetrics& rhs) { + return lhs.width == rhs.width && + lhs.height == rhs.height && + lhs.left == rhs.left && + lhs.top == rhs.top && + lhs.advance == rhs.advance; +} + struct Glyph { explicit Glyph() : rect(0, 0, 0, 0), metrics() {} explicit Glyph(Rect<uint16_t> rect_, GlyphMetrics metrics_) : rect(std::move(rect_)), metrics(std::move(metrics_)) {} - operator bool() const { + explicit operator bool() const { return metrics || rect.hasArea(); } @@ -64,7 +72,7 @@ class Shaping { int32_t left; int32_t right; - operator bool() const { return !positionedGlyphs.empty(); } + explicit operator bool() const { return !positionedGlyphs.empty(); } }; class SDFGlyph { |