From f1ac757bd28351fd57113a1e16f6c2e00ab193c1 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 11 Jul 2017 15:11:14 +0300 Subject: [core] GCC 4.9 does not fully support custom variable templates --- include/mbgl/style/conversion/function.hpp | 2 +- include/mbgl/style/function/camera_function.hpp | 2 +- include/mbgl/style/function/composite_function.hpp | 4 ++-- include/mbgl/style/function/source_function.hpp | 2 +- include/mbgl/util/indexed_tuple.hpp | 7 ++----- include/mbgl/util/interpolate.hpp | 6 +++++- src/mbgl/gl/attribute.cpp | 20 +++++++++++--------- src/mbgl/gl/attribute.hpp | 5 +---- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/mbgl/style/conversion/function.hpp b/include/mbgl/style/conversion/function.hpp index bf5b27a9a6..752b6dd045 100644 --- a/include/mbgl/style/conversion/function.hpp +++ b/include/mbgl/style/conversion/function.hpp @@ -156,7 +156,7 @@ struct StopsConverter> { public: template optional> operator()(const V& value, Error& error) const { - std::string type = util::Interpolatable ? "exponential" : "interval"; + std::string type = util::Interpolatable::value ? "exponential" : "interval"; auto typeValue = objectMember(value, "type"); if (typeValue && toString(*typeValue)) { diff --git a/include/mbgl/style/function/camera_function.hpp b/include/mbgl/style/function/camera_function.hpp index 0fd5bcb078..7fde365b3d 100644 --- a/include/mbgl/style/function/camera_function.hpp +++ b/include/mbgl/style/function/camera_function.hpp @@ -12,7 +12,7 @@ template class CameraFunction { public: using Stops = std::conditional_t< - util::Interpolatable, + util::Interpolatable::value, variant< ExponentialStops, IntervalStops>, diff --git a/include/mbgl/style/function/composite_function.hpp b/include/mbgl/style/function/composite_function.hpp index 43599cd333..7b524b6021 100644 --- a/include/mbgl/style/function/composite_function.hpp +++ b/include/mbgl/style/function/composite_function.hpp @@ -24,7 +24,7 @@ template class CompositeFunction { public: using InnerStops = std::conditional_t< - util::Interpolatable, + util::Interpolatable::value, variant< ExponentialStops, IntervalStops, @@ -34,7 +34,7 @@ public: CategoricalStops>>; using Stops = std::conditional_t< - util::Interpolatable, + util::Interpolatable::value, variant< CompositeExponentialStops, CompositeIntervalStops, diff --git a/include/mbgl/style/function/source_function.hpp b/include/mbgl/style/function/source_function.hpp index 2872c63a64..9c2ad101ec 100644 --- a/include/mbgl/style/function/source_function.hpp +++ b/include/mbgl/style/function/source_function.hpp @@ -16,7 +16,7 @@ template class SourceFunction { public: using Stops = std::conditional_t< - util::Interpolatable, + util::Interpolatable::value, variant< ExponentialStops, IntervalStops, diff --git a/include/mbgl/util/indexed_tuple.hpp b/include/mbgl/util/indexed_tuple.hpp index a414639530..fd0b931d36 100644 --- a/include/mbgl/util/indexed_tuple.hpp +++ b/include/mbgl/util/indexed_tuple.hpp @@ -30,17 +30,14 @@ public: using std::tuple::tuple; - template - static constexpr std::size_t Index = TypeIndex::value; - template auto& get() { - return std::get>(*this); + return std::get::value>(*this); } template const auto& get() const { - return std::get>(*this); + return std::get::value>(*this); } template diff --git a/include/mbgl/util/interpolate.hpp b/include/mbgl/util/interpolate.hpp index a2103f18b2..6738987598 100644 --- a/include/mbgl/util/interpolate.hpp +++ b/include/mbgl/util/interpolate.hpp @@ -95,7 +95,11 @@ struct Interpolator> : Uninterpolated {}; template -constexpr bool Interpolatable = !std::is_base_of>::value; +struct Interpolatable + : std::conditional_t< + !std::is_base_of>::value, + std::true_type, + std::false_type> {}; } // namespace util } // namespace mbgl diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp index 4e6f78e689..4569e3cb32 100644 --- a/src/mbgl/gl/attribute.cpp +++ b/src/mbgl/gl/attribute.cpp @@ -55,14 +55,16 @@ void DisabledAttribute::bind(Context&, AttributeLocation location, std::size_t) MBGL_CHECK_ERROR(glDisableVertexAttribArray(location)); } -template DataType DataTypeOf = static_cast(0); -template <> DataType DataTypeOf< int8_t> = DataType::Byte; -template <> DataType DataTypeOf = DataType::UnsignedByte; -template <> DataType DataTypeOf< int16_t> = DataType::Short; -template <> DataType DataTypeOf = DataType::UnsignedShort; -template <> DataType DataTypeOf< int32_t> = DataType::Integer; -template <> DataType DataTypeOf = DataType::UnsignedInteger; -template <> DataType DataTypeOf = DataType::Float; +template +constexpr DataType DataTypeOf() { + return std::is_same::value ? DataType::Byte : + std::is_same::value ? DataType::UnsignedByte : + std::is_same::value ? DataType::Short : + std::is_same::value ? DataType::UnsignedShort : + std::is_same::value ? DataType::Integer : + std::is_same::value ? DataType::UnsignedInteger : + std::is_same::value ? DataType::Float : static_cast(0); +} template void AttributeBinding::bind(Context& context, AttributeLocation location, std::size_t vertexOffset) const { @@ -76,7 +78,7 @@ void AttributeBinding::bind(Context& context, AttributeLocation location, MBGL_CHECK_ERROR(glVertexAttribPointer( location, static_cast(attributeSize), - static_cast(DataTypeOf), + static_cast(DataTypeOf()), static_cast(false), static_cast(vertexSize), reinterpret_cast(attributeOffset + (vertexSize * vertexOffset)))); diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp index f018a1d261..bc02b54bd2 100644 --- a/src/mbgl/gl/attribute.hpp +++ b/src/mbgl/gl/attribute.hpp @@ -240,9 +240,6 @@ public: using Vertex = detail::Vertex; - template - static constexpr std::size_t Index = TypeIndex::value; - static Locations bindLocations(const ProgramID& id) { std::set activeAttributes = getActiveAttributes(id); @@ -266,7 +263,7 @@ public: template static Bindings bindings(const VertexBuffer& buffer) { - return Bindings { As::Type::binding(buffer, Index)... }; + return Bindings { As::Type::binding(buffer, TypeIndex::value)... }; } static void bind(Context& context, -- cgit v1.2.1