Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] GCC 4.9 does not fully support custom variable templates
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Jul 12, 2017
1 parent 1aacc88 commit f1ac757
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion include/mbgl/style/conversion/function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ struct StopsConverter<T, variant<Ts...>> {
public:
template <class V>
optional<variant<Ts...>> operator()(const V& value, Error& error) const {
std::string type = util::Interpolatable<T> ? "exponential" : "interval";
std::string type = util::Interpolatable<T>::value ? "exponential" : "interval";

auto typeValue = objectMember(value, "type");
if (typeValue && toString(*typeValue)) {
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/style/function/camera_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ template <class T>
class CameraFunction {
public:
using Stops = std::conditional_t<
util::Interpolatable<T>,
util::Interpolatable<T>::value,
variant<
ExponentialStops<T>,
IntervalStops<T>>,
Expand Down
4 changes: 2 additions & 2 deletions include/mbgl/style/function/composite_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ template <class T>
class CompositeFunction {
public:
using InnerStops = std::conditional_t<
util::Interpolatable<T>,
util::Interpolatable<T>::value,
variant<
ExponentialStops<T>,
IntervalStops<T>,
Expand All @@ -34,7 +34,7 @@ class CompositeFunction {
CategoricalStops<T>>>;

using Stops = std::conditional_t<
util::Interpolatable<T>,
util::Interpolatable<T>::value,
variant<
CompositeExponentialStops<T>,
CompositeIntervalStops<T>,
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/style/function/source_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ template <class T>
class SourceFunction {
public:
using Stops = std::conditional_t<
util::Interpolatable<T>,
util::Interpolatable<T>::value,
variant<
ExponentialStops<T>,
IntervalStops<T>,
Expand Down
7 changes: 2 additions & 5 deletions include/mbgl/util/indexed_tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@ class IndexedTuple<TypeList<Is...>, TypeList<Ts...>> : public std::tuple<Ts...>

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);
}

template <class... Js, class... Us>
Expand Down
6 changes: 5 additions & 1 deletion include/mbgl/util/interpolate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ struct Interpolator<std::vector<T>>
: Uninterpolated {};

template <class T>
constexpr bool Interpolatable = !std::is_base_of<Uninterpolated, Interpolator<T>>::value;
struct Interpolatable
: std::conditional_t<
!std::is_base_of<Uninterpolated, Interpolator<T>>::value,
std::true_type,
std::false_type> {};

} // namespace util
} // namespace mbgl
20 changes: 11 additions & 9 deletions src/mbgl/gl/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ void DisabledAttribute::bind(Context&, AttributeLocation location, std::size_t)
MBGL_CHECK_ERROR(glDisableVertexAttribArray(location));
}

template <class T> DataType DataTypeOf = static_cast<DataType>(0);
template <> DataType DataTypeOf< int8_t> = DataType::Byte;
template <> DataType DataTypeOf<uint8_t> = DataType::UnsignedByte;
template <> DataType DataTypeOf< int16_t> = DataType::Short;
template <> DataType DataTypeOf<uint16_t> = DataType::UnsignedShort;
template <> DataType DataTypeOf< int32_t> = DataType::Integer;
template <> DataType DataTypeOf<uint32_t> = DataType::UnsignedInteger;
template <> DataType DataTypeOf<float> = DataType::Float;
template <class T>
constexpr DataType DataTypeOf() {
return std::is_same<T, int8_t>::value ? DataType::Byte :
std::is_same<T, uint8_t>::value ? DataType::UnsignedByte :
std::is_same<T, int16_t>::value ? DataType::Short :
std::is_same<T, uint16_t>::value ? DataType::UnsignedShort :
std::is_same<T, int32_t>::value ? DataType::Integer :
std::is_same<T, uint32_t>::value ? DataType::UnsignedInteger :
std::is_same<T, float>::value ? DataType::Float : static_cast<DataType>(0);
}

template <class T, std::size_t N>
void AttributeBinding<T, N>::bind(Context& context, AttributeLocation location, std::size_t vertexOffset) const {
Expand All @@ -76,7 +78,7 @@ void AttributeBinding<T, N>::bind(Context& context, AttributeLocation location,
MBGL_CHECK_ERROR(glVertexAttribPointer(
location,
static_cast<GLint>(attributeSize),
static_cast<GLenum>(DataTypeOf<T>),
static_cast<GLenum>(DataTypeOf<T>()),
static_cast<GLboolean>(false),
static_cast<GLsizei>(vertexSize),
reinterpret_cast<GLvoid*>(attributeOffset + (vertexSize * vertexOffset))));
Expand Down
5 changes: 1 addition & 4 deletions src/mbgl/gl/attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ class Attributes {

using Vertex = detail::Vertex<typename As::Type...>;

template <class A>
static constexpr std::size_t Index = TypeIndex<A, As...>::value;

static Locations bindLocations(const ProgramID& id) {
std::set<std::string> activeAttributes = getActiveAttributes(id);

Expand All @@ -266,7 +263,7 @@ class Attributes {

template <class DrawMode>
static Bindings bindings(const VertexBuffer<Vertex, DrawMode>& buffer) {
return Bindings { As::Type::binding(buffer, Index<As>)... };
return Bindings { As::Type::binding(buffer, TypeIndex<As, As...>::value)... };
}

static void bind(Context& context,
Expand Down

0 comments on commit f1ac757

Please sign in to comment.