[core] Added mbgl::underlying_type
This commit is contained in:
@@ -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
|
||||
|
||||
15
include/mbgl/util/traits.hpp
Normal file
15
include/mbgl/util/traits.hpp
Normal file
@@ -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
|
||||
@@ -1,8 +1,9 @@
|
||||
#ifndef MBGL_RENDERER_RENDER_PASS
|
||||
#define MBGL_RENDERER_RENDER_PASS
|
||||
|
||||
#include <mbgl/util/traits.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -13,8 +14,7 @@ enum class RenderPass : uint8_t {
|
||||
};
|
||||
|
||||
constexpr inline RenderPass operator|(RenderPass a, RenderPass b) {
|
||||
return static_cast<RenderPass>(static_cast<std::underlying_type<RenderPass>::type>(a) |
|
||||
static_cast<std::underlying_type<RenderPass>::type>(b));
|
||||
return static_cast<RenderPass>(mbgl::underlying_type(a) | mbgl::underlying_type(b));
|
||||
}
|
||||
|
||||
inline RenderPass operator|=(RenderPass& a, RenderPass b) {
|
||||
@@ -22,8 +22,7 @@ inline RenderPass operator|=(RenderPass& a, RenderPass b) {
|
||||
}
|
||||
|
||||
constexpr inline RenderPass operator&(RenderPass a, RenderPass b) {
|
||||
return static_cast<RenderPass>(static_cast<std::underlying_type<RenderPass>::type>(a) &
|
||||
static_cast<std::underlying_type<RenderPass>::type>(b));
|
||||
return static_cast<RenderPass>(mbgl::underlying_type(a) & mbgl::underlying_type(b));
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
Reference in New Issue
Block a user