[core] introduce TypeListConcat and TypeList::ExpandInto

This commit is contained in:
Konstantin Käfer
2018-06-01 11:49:15 +02:00
committed by Molly Lloyd
parent 748e6bde5f
commit 5e9bbfdd44
6 changed files with 36 additions and 46 deletions

View File

@@ -5,8 +5,11 @@
namespace mbgl {
template <class...>
class TypeList {};
template <class... Ts>
struct TypeList {
template <template <class...> class T, class... Ps>
using ExpandInto = T<Ps..., Ts...>;
};
namespace detail {
@@ -32,9 +35,30 @@ struct TypeFilter<TypeList<T, Ts...>, Predicate> {
using Type = std::conditional_t<Predicate<T>::value, typename TypeCons<T, Tail>::Type, Tail>;
};
template <class...>
struct TypeListConcat;
template <>
struct TypeListConcat<> {
using Type = TypeList<>;
};
template <class... As>
struct TypeListConcat<TypeList<As...>> {
using Type = TypeList<As...>;
};
template <class... As, class... Bs, class... Rs>
struct TypeListConcat<TypeList<As...>, TypeList<Bs...>, Rs...> {
using Type = typename TypeListConcat<TypeList<As..., Bs...>, Rs...>::Type;
};
} // namespace detail
template <class TypeList, template <class> class Predicate>
using FilteredTypeList = typename detail::TypeFilter<TypeList, Predicate>::Type;
template <class... Ts>
using TypeListConcat = typename detail::TypeListConcat<Ts...>::Type;
} // namespace mbgl

View File

@@ -294,22 +294,8 @@ public:
}
};
namespace detail {
template <class...>
struct ConcatenateAttributes;
template <class... As, class... Bs>
struct ConcatenateAttributes<TypeList<As...>, TypeList<Bs...>> {
using Type = Attributes<As..., Bs...>;
};
} // namespace detail
template <class A, class B>
using ConcatenateAttributes = typename detail::ConcatenateAttributes<
typename A::Types,
typename B::Types>::Type;
template <class... As>
using ConcatenateAttributes = typename TypeListConcat<typename As::Types...>::template ExpandInto<Attributes>;
} // namespace gl
} // namespace mbgl

View File

@@ -120,23 +120,8 @@ public:
}
};
namespace detail {
template <class...>
struct ConcatenateUniforms;
template <class... As, class... Bs>
struct ConcatenateUniforms<TypeList<As...>, TypeList<Bs...>> {
using Type = Uniforms<As..., Bs...>;
};
} // namespace detail
template <class A, class B>
using ConcatenateUniforms = typename detail::ConcatenateUniforms<
typename A::Types,
typename B::Types>::Type;
template <class... Us>
using ConcatenateUniforms = typename TypeListConcat<typename Us::Types...>::template ExpandInto<Uniforms>;
} // namespace gl
} // namespace mbgl

View File

@@ -252,7 +252,7 @@ public:
using LayoutAttributes = LayoutAttrs;
using LayoutVertex = typename LayoutAttributes::Vertex;
using LayoutAndSizeAttributes = gl::ConcatenateAttributes<LayoutAttributes, gl::ConcatenateAttributes<SymbolDynamicLayoutAttributes, SymbolOpacityAttributes>>;
using LayoutAndSizeAttributes = gl::ConcatenateAttributes<LayoutAttributes, SymbolDynamicLayoutAttributes, SymbolOpacityAttributes>;
using PaintProperties = PaintProps;
using PaintPropertyBinders = typename PaintProperties::Binders;
@@ -262,7 +262,7 @@ public:
using UniformValues = typename Uniforms::Values;
using SizeUniforms = typename SymbolSizeBinder::Uniforms;
using PaintUniforms = typename PaintPropertyBinders::Uniforms;
using AllUniforms = gl::ConcatenateUniforms<Uniforms, gl::ConcatenateUniforms<SizeUniforms, PaintUniforms>>;
using AllUniforms = gl::ConcatenateUniforms<Uniforms, SizeUniforms, PaintUniforms>;
using ProgramType = gl::Program<Primitive, Attributes, AllUniforms>;

View File

@@ -13,8 +13,8 @@ struct LineFloorwidth : style::DataDrivenPaintProperty<float, attributes::a_floo
};
class RenderLinePaintProperties : public style::ConcatenateProperties<
style::LinePaintProperties::PropertyTypes,
TypeList<LineFloorwidth>>::Type {};
style::LinePaintProperties,
style::Properties<LineFloorwidth>> {};
class RenderLineLayer: public RenderLayer {
public:

View File

@@ -233,13 +233,8 @@ public:
};
};
template <class...>
struct ConcatenateProperties;
template <class... As, class... Bs>
struct ConcatenateProperties<TypeList<As...>, TypeList<Bs...>> {
using Type = Properties<As..., Bs...>;
};
template <class... Ps>
using ConcatenateProperties = typename TypeListConcat<typename Ps::PropertyTypes...>::template ExpandInto<Properties>;
} // namespace style
} // namespace mbgl