[core] Added MBGL_CONSTEXPR to satisfy GCC 4.9

This commit is contained in:
Bruno de Oliveira Abinader
2017-07-11 15:32:51 +03:00
parent d918f8d7c2
commit 6282b28b6f
7 changed files with 32 additions and 18 deletions

View File

@@ -1,5 +1,6 @@
#pragma once
#include <mbgl/util/util.hpp>
#include <mbgl/util/traits.hpp>
#include <cstdint>
@@ -51,23 +52,23 @@ enum class MapDebugOptions : EnumType {
#endif // MBGL_USE_GLES2
};
constexpr MapDebugOptions operator|(MapDebugOptions lhs, MapDebugOptions rhs) {
MBGL_CONSTEXPR MapDebugOptions operator|(MapDebugOptions lhs, MapDebugOptions rhs) {
return MapDebugOptions(mbgl::underlying_type(lhs) | mbgl::underlying_type(rhs));
}
constexpr MapDebugOptions& operator|=(MapDebugOptions& lhs, MapDebugOptions rhs) {
MBGL_CONSTEXPR MapDebugOptions& operator|=(MapDebugOptions& lhs, MapDebugOptions rhs) {
return (lhs = MapDebugOptions(mbgl::underlying_type(lhs) | mbgl::underlying_type(rhs)));
}
constexpr bool operator&(MapDebugOptions lhs, MapDebugOptions rhs) {
MBGL_CONSTEXPR bool operator&(MapDebugOptions lhs, MapDebugOptions rhs) {
return mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs);
}
constexpr MapDebugOptions& operator&=(MapDebugOptions& lhs, MapDebugOptions rhs) {
MBGL_CONSTEXPR MapDebugOptions& operator&=(MapDebugOptions& lhs, MapDebugOptions rhs) {
return (lhs = MapDebugOptions(mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs)));
}
constexpr MapDebugOptions operator~(MapDebugOptions value) {
MBGL_CONSTEXPR MapDebugOptions operator~(MapDebugOptions value) {
return MapDebugOptions(~mbgl::underlying_type(value));
}

View File

@@ -1,3 +1,5 @@
#include <mbgl/util/util.hpp>
#include <array>
#include <type_traits>
#include <utility>
@@ -7,7 +9,7 @@ namespace util {
template<typename To, typename From, std::size_t Size,
typename = std::enable_if_t<std::is_convertible<From, To>::value>>
constexpr std::array<To, Size> convert(const std::array<From, Size>&from) {
MBGL_CONSTEXPR std::array<To, Size> convert(const std::array<From, Size>&from) {
std::array<To, Size> to {};
std::copy(std::begin(from), std::end(from), std::begin(to));
return to;

View File

@@ -12,3 +12,10 @@
#define MBGL_VERIFY_THREAD(tid)
#endif
// GCC 4.9 compatibility
#if !defined(__GNUC__) || __GNUC__ >= 5
#define MBGL_CONSTEXPR constexpr
#else
#define MBGL_CONSTEXPR inline
#endif

View File

@@ -1,12 +1,13 @@
#include <mbgl/gl/gl.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/util.hpp>
namespace mbgl {
namespace gl {
namespace {
constexpr const char* stringFromError(GLenum err) {
MBGL_CONSTEXPR const char* stringFromError(GLenum err) {
switch (err) {
case GL_INVALID_ENUM:
return "GL_INVALID_ENUM";

View File

@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/util/traits.hpp>
#include <mbgl/util/util.hpp>
namespace mbgl {
@@ -11,15 +12,15 @@ enum class Update {
AnnotationData = 1 << 7
};
constexpr Update operator|(Update lhs, Update rhs) {
MBGL_CONSTEXPR Update operator|(Update lhs, Update rhs) {
return Update(mbgl::underlying_type(lhs) | mbgl::underlying_type(rhs));
}
constexpr Update& operator|=(Update& lhs, const Update& rhs) {
MBGL_CONSTEXPR Update& operator|=(Update& lhs, const Update& rhs) {
return (lhs = lhs | rhs);
}
constexpr bool operator& (Update lhs, Update rhs) {
MBGL_CONSTEXPR bool operator& (Update lhs, Update rhs) {
return mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs);
}

View File

@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/util/traits.hpp>
#include <mbgl/util/util.hpp>
#include <cstdint>
@@ -12,15 +13,15 @@ enum class RenderPass : uint8_t {
Translucent = 1 << 1,
};
constexpr RenderPass operator|(RenderPass a, RenderPass b) {
MBGL_CONSTEXPR RenderPass operator|(RenderPass a, RenderPass b) {
return RenderPass(mbgl::underlying_type(a) | mbgl::underlying_type(b));
}
constexpr RenderPass& operator|=(RenderPass& a, RenderPass b) {
MBGL_CONSTEXPR RenderPass& operator|=(RenderPass& a, RenderPass b) {
return (a = a | b);
}
constexpr RenderPass operator&(RenderPass a, RenderPass b) {
MBGL_CONSTEXPR RenderPass operator&(RenderPass a, RenderPass b) {
return RenderPass(mbgl::underlying_type(a) & mbgl::underlying_type(b));
}

View File

@@ -7,6 +7,7 @@
#include <mbgl/util/optional.hpp>
#include <mbgl/util/immutable.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/util.hpp>
#include <cstdint>
#include <vector>
@@ -89,23 +90,23 @@ enum class WritingModeType : uint8_t {
Vertical = 1 << 1,
};
constexpr WritingModeType operator|(WritingModeType a, WritingModeType b) {
MBGL_CONSTEXPR WritingModeType operator|(WritingModeType a, WritingModeType b) {
return WritingModeType(mbgl::underlying_type(a) | mbgl::underlying_type(b));
}
constexpr WritingModeType& operator|=(WritingModeType& a, WritingModeType b) {
MBGL_CONSTEXPR WritingModeType& operator|=(WritingModeType& a, WritingModeType b) {
return (a = a | b);
}
constexpr bool operator&(WritingModeType lhs, WritingModeType rhs) {
MBGL_CONSTEXPR bool operator&(WritingModeType lhs, WritingModeType rhs) {
return mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs);
}
constexpr WritingModeType& operator&=(WritingModeType& lhs, WritingModeType rhs) {
MBGL_CONSTEXPR WritingModeType& operator&=(WritingModeType& lhs, WritingModeType rhs) {
return (lhs = WritingModeType(mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs)));
}
constexpr WritingModeType operator~(WritingModeType value) {
MBGL_CONSTEXPR WritingModeType operator~(WritingModeType value) {
return WritingModeType(~mbgl::underlying_type(value));
}