summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-04-28 18:24:24 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-04-28 18:55:55 +0300
commit1f5587b3ea23d03364107f39b24ff16545d04dd7 (patch)
tree9c6c5690c9494389ecf66f00c6b94e301fae7864 /include
parentffb59864dc04e235c898465dbcb8250ff776a7c9 (diff)
downloadqtlocation-mapboxgl-1f5587b3ea23d03364107f39b24ff16545d04dd7.tar.gz
[core] Added mbgl::underlying_type
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/map/update.hpp6
-rw-r--r--include/mbgl/util/traits.hpp15
2 files changed, 19 insertions, 2 deletions
diff --git a/include/mbgl/map/update.hpp b/include/mbgl/map/update.hpp
index e47feea949..4ad1b1d195 100644
--- a/include/mbgl/map/update.hpp
+++ b/include/mbgl/map/update.hpp
@@ -1,6 +1,8 @@
#ifndef MBGL_MAP_UPDATE
#define MBGL_MAP_UPDATE
+#include <mbgl/util/traits.hpp>
+
#include <cstdint>
namespace mbgl {
@@ -16,7 +18,7 @@ enum class Update : uint8_t {
};
inline Update operator| (const Update& lhs, const Update& rhs) {
- return Update(static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
+ return Update(mbgl::underlying_type(lhs) | mbgl::underlying_type(rhs));
}
inline Update& operator|=(Update& lhs, const Update& rhs) {
@@ -25,7 +27,7 @@ inline Update& operator|=(Update& lhs, const Update& rhs) {
}
inline bool operator& (const Update& lhs, const Update& rhs) {
- return static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs);
+ return mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs);
}
} // namespace mbgl
diff --git a/include/mbgl/util/traits.hpp b/include/mbgl/util/traits.hpp
new file mode 100644
index 0000000000..812d9fb547
--- /dev/null
+++ b/include/mbgl/util/traits.hpp
@@ -0,0 +1,15 @@
+#ifndef MBGL_UTIL_TRAITS
+#define MBGL_UTIL_TRAITS
+
+#include <type_traits>
+
+namespace mbgl {
+
+template<typename T>
+constexpr auto underlying_type(T t) -> typename std::underlying_type<T>::type {
+ return static_cast<typename std::underlying_type<T>::type>(t);
+}
+
+} // namespace mbgl
+
+#endif // MBGL_UTIL_TRAITS