summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2016-12-20 15:01:13 -0200
committerThiago Marcos P. Santos <thiago@mapbox.com>2017-01-24 11:36:59 +0200
commit9833ca8b76e9608ba9c3a8928de93b1fb9be3a45 (patch)
treed68c2d91b80a91870356e0d54039bd98a111740b
parent4dd6b704223e14762fb68b23f29ad9d644bfcc93 (diff)
downloadqtlocation-mapboxgl-9833ca8b76e9608ba9c3a8928de93b1fb9be3a45.tar.gz
[gcc4.9] Make constexpr usage compatible with GCC 4.9
-rw-r--r--include/mbgl/map/mode.hpp11
-rw-r--r--include/mbgl/util/color.hpp1
-rw-r--r--include/mbgl/util/constants.hpp3
-rw-r--r--include/mbgl/util/convert.hpp4
-rw-r--r--include/mbgl/util/unitbezier.hpp4
-rw-r--r--include/mbgl/util/util.hpp7
-rw-r--r--src/mbgl/gl/attribute.hpp7
-rw-r--r--src/mbgl/gl/gl.cpp3
-rw-r--r--src/mbgl/map/update.hpp7
-rw-r--r--src/mbgl/renderer/render_pass.hpp7
-rw-r--r--src/mbgl/util/indexed_tuple.hpp7
11 files changed, 36 insertions, 25 deletions
diff --git a/include/mbgl/map/mode.hpp b/include/mbgl/map/mode.hpp
index afec5c0a08..05de2df22c 100644
--- a/include/mbgl/map/mode.hpp
+++ b/include/mbgl/map/mode.hpp
@@ -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));
}
diff --git a/include/mbgl/util/color.hpp b/include/mbgl/util/color.hpp
index 300d7fae82..b595fdb1d7 100644
--- a/include/mbgl/util/color.hpp
+++ b/include/mbgl/util/color.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/util/optional.hpp>
+#include <mbgl/util/util.hpp>
#include <cassert>
#include <string>
diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp
index 85e19c2ff0..a5a83287bc 100644
--- a/include/mbgl/util/constants.hpp
+++ b/include/mbgl/util/constants.hpp
@@ -2,6 +2,7 @@
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/unitbezier.hpp>
+#include <mbgl/util/util.hpp>
#include <cmath>
#include <string>
@@ -43,7 +44,7 @@ constexpr uint64_t DEFAULT_MAX_CACHE_SIZE = 50 * 1024 * 1024;
constexpr Duration DEFAULT_FADE_DURATION = Milliseconds(300);
constexpr Seconds CLOCK_SKEW_RETRY_TIMEOUT { 30 };
-constexpr UnitBezier DEFAULT_TRANSITION_EASE = { 0, 0, 0.25, 1 };
+const UnitBezier DEFAULT_TRANSITION_EASE = { 0, 0, 0.25, 1 };
constexpr int DEFAULT_RATE_LIMIT_TIMEOUT = 5;
diff --git a/include/mbgl/util/convert.hpp b/include/mbgl/util/convert.hpp
index c2b3d9950d..bedb1a4a08 100644
--- a/include/mbgl/util/convert.hpp
+++ b/include/mbgl/util/convert.hpp
@@ -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;
diff --git a/include/mbgl/util/unitbezier.hpp b/include/mbgl/util/unitbezier.hpp
index 3a4994917b..16e356ac6e 100644
--- a/include/mbgl/util/unitbezier.hpp
+++ b/include/mbgl/util/unitbezier.hpp
@@ -25,6 +25,8 @@
#pragma once
+#include <mbgl/util/util.hpp>
+
#include <cmath>
namespace mbgl {
@@ -32,7 +34,7 @@ namespace util {
struct UnitBezier {
// Calculate the polynomial coefficients, implicit first and last control points are (0,0) and (1,1).
- constexpr UnitBezier(double p1x, double p1y, double p2x, double p2y)
+ MBGL_CONSTEXPR UnitBezier(double p1x, double p1y, double p2x, double p2y)
: cx(3.0 * p1x)
, bx(3.0 * (p2x - p1x) - cx)
, ax(1.0 - cx - bx)
diff --git a/include/mbgl/util/util.hpp b/include/mbgl/util/util.hpp
index c5a7cb3780..7960b40299 100644
--- a/include/mbgl/util/util.hpp
+++ b/include/mbgl/util/util.hpp
@@ -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
diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp
index e45014127b..95945bca64 100644
--- a/src/mbgl/gl/attribute.hpp
+++ b/src/mbgl/gl/attribute.hpp
@@ -148,11 +148,8 @@ public:
using State = IndexedTuple<TypeList<As...>, TypeList<typename As::State...>>;
using Vertex = detail::Vertex<As...>;
- template <class A>
- static constexpr std::size_t Index = TypeIndex<A, As...>::value;
-
static State state(const ProgramID& id) {
- return State { typename As::State(bindAttributeLocation(id, Index<As>, As::name))... };
+ return State { typename As::State(bindAttributeLocation(id, TypeIndex<As, As...>::value, As::name))... };
}
static std::function<void (std::size_t)> binder(const State& state) {
@@ -162,7 +159,7 @@ public:
state.template get<As>().type,
sizeof(Vertex),
vertexOffset,
- Vertex::attributeOffsets[Index<As>]), 0)... });
+ Vertex::attributeOffsets[TypeIndex<As, As...>::value]), 0)... });
};
}
};
diff --git a/src/mbgl/gl/gl.cpp b/src/mbgl/gl/gl.cpp
index 8999468dbd..bd6d7b192d 100644
--- a/src/mbgl/gl/gl.cpp
+++ b/src/mbgl/gl/gl.cpp
@@ -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";
diff --git a/src/mbgl/map/update.hpp b/src/mbgl/map/update.hpp
index 74ab22dd8a..6f7c103cb8 100644
--- a/src/mbgl/map/update.hpp
+++ b/src/mbgl/map/update.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/util/traits.hpp>
+#include <mbgl/util/util.hpp>
namespace mbgl {
@@ -14,15 +15,15 @@ enum class Update {
Layout = 1 << 8
};
-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);
}
diff --git a/src/mbgl/renderer/render_pass.hpp b/src/mbgl/renderer/render_pass.hpp
index d273e34ff7..ae2b923ba1 100644
--- a/src/mbgl/renderer/render_pass.hpp
+++ b/src/mbgl/renderer/render_pass.hpp
@@ -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));
}
diff --git a/src/mbgl/util/indexed_tuple.hpp b/src/mbgl/util/indexed_tuple.hpp
index 110e7dce12..c46f63f275 100644
--- a/src/mbgl/util/indexed_tuple.hpp
+++ b/src/mbgl/util/indexed_tuple.hpp
@@ -31,16 +31,13 @@ public:
using std::tuple<Ts...>::tuple;
template <class I>
- static constexpr std::size_t Index = TypeIndex<I, Is...>::value;
-
- template <class I>
auto& get() {
- return std::get<Index<I>>(*this);
+ return std::get<TypeIndex<I, Is...>::value>(*this);
}
template <class I>
const auto& get() const {
- return std::get<Index<I>>(*this);
+ return std::get<TypeIndex<I, Is...>::value>(*this);
}
};