diff --git a/include/mbgl/style/filter_expression.hpp b/include/mbgl/style/filter_expression.hpp index 2a6a2927e..2a9657879 100644 --- a/include/mbgl/style/filter_expression.hpp +++ b/include/mbgl/style/filter_expression.hpp @@ -10,7 +10,7 @@ namespace mbgl { class FilterExpression { public: - typedef util::recursive_wrapper Wrapper; + typedef mapbox::util::recursive_wrapper Wrapper; enum class Operator : uint8_t { And, diff --git a/include/mbgl/style/function_properties.hpp b/include/mbgl/style/function_properties.hpp index 8cd7ce6e2..56092f9a6 100644 --- a/include/mbgl/style/function_properties.hpp +++ b/include/mbgl/style/function_properties.hpp @@ -27,7 +27,7 @@ private: }; template -using Function = util::variant< +using Function = mapbox::util::variant< std::false_type, ConstantFunction, StopsFunction diff --git a/include/mbgl/style/property_value.hpp b/include/mbgl/style/property_value.hpp index 4d148dc02..1b22b3117 100644 --- a/include/mbgl/style/property_value.hpp +++ b/include/mbgl/style/property_value.hpp @@ -7,7 +7,7 @@ namespace mbgl { -typedef util::variant< +typedef mapbox::util::variant< std::string, TranslateAnchorType, RotateAnchorType, diff --git a/include/mbgl/style/style_bucket.hpp b/include/mbgl/style/style_bucket.hpp index 58d4d705d..67c314205 100644 --- a/include/mbgl/style/style_bucket.hpp +++ b/include/mbgl/style/style_bucket.hpp @@ -89,8 +89,8 @@ public: float buffer = 0.03125f; }; -typedef util::variant StyleBucketRender; +typedef mapbox::util::variant StyleBucketRender; class StyleBucket { diff --git a/include/mbgl/style/style_properties.hpp b/include/mbgl/style/style_properties.hpp index 742ae63f0..bbe8812bc 100644 --- a/include/mbgl/style/style_properties.hpp +++ b/include/mbgl/style/style_properties.hpp @@ -95,7 +95,7 @@ struct BackgroundProperties { Color color = {{ 0, 0, 0, 1 }}; }; -typedef util::variant< +typedef mapbox::util::variant< FillProperties, LineProperties, SymbolProperties, diff --git a/include/mbgl/style/value.hpp b/include/mbgl/style/value.hpp index 5e6260e5a..b981f1db9 100644 --- a/include/mbgl/style/value.hpp +++ b/include/mbgl/style/value.hpp @@ -9,7 +9,7 @@ namespace mbgl { -typedef util::variant Value; +typedef mapbox::util::variant Value; std::string toString(const Value &value); diff --git a/include/mbgl/util/recursive_wrapper.hpp b/include/mbgl/util/recursive_wrapper.hpp index a616805c0..54b27634a 100644 --- a/include/mbgl/util/recursive_wrapper.hpp +++ b/include/mbgl/util/recursive_wrapper.hpp @@ -3,7 +3,7 @@ #include -namespace mbgl { namespace util { +namespace mapbox { namespace util { template class recursive_wrapper diff --git a/include/mbgl/util/variant.hpp b/include/mbgl/util/variant.hpp index ddc82ee31..1eca5160c 100644 --- a/include/mbgl/util/variant.hpp +++ b/include/mbgl/util/variant.hpp @@ -35,7 +35,7 @@ // translates to 100 #define VARIANT_VERSION (VARIANT_MAJOR_VERSION*100000) + (VARIANT_MINOR_VERSION*100) + (VARIANT_PATCH_VERSION) -namespace mbgl { namespace util { namespace detail { +namespace mapbox { namespace util { namespace detail { static constexpr std::size_t invalid_value = std::size_t(-1); @@ -487,6 +487,8 @@ private: } // namespace detail +struct no_init {}; + template class variant { @@ -503,12 +505,16 @@ private: public: + VARIANT_INLINE variant() : type_index(sizeof...(Types) - 1) { new (&data) typename detail::select_type<0, Types...>::type(); } + VARIANT_INLINE variant(no_init) + : type_index(detail::invalid_value) {} + template ::value>::type> VARIANT_INLINE explicit variant(T const& val) noexcept @@ -715,11 +721,24 @@ auto VARIANT_INLINE static apply_visitor(F f, V & v0, V & v1) -> decltype(V::bin return V::binary_visit(v0, v1, f); } +// getter interface +template +ResultType & get(T & var) +{ + return var.template get(); +} + +template +ResultType const& get(T const& var) +{ + return var.template get(); +} + // operator<< -template +template VARIANT_INLINE std::basic_ostream& -operator<< (std::basic_ostream& out, Variant const& rhs) +operator<< (std::basic_ostream& out, variant const& rhs) { detail::printer> visitor(out); apply_visitor(visitor, rhs); diff --git a/src/style/style_layer.cpp b/src/style/style_layer.cpp index d4e6d19db..4994cf3ef 100644 --- a/src/style/style_layer.cpp +++ b/src/style/style_layer.cpp @@ -105,7 +105,7 @@ struct PropertyEvaluator { } T operator()(const Function &value) const { - return util::apply_visitor(FunctionEvaluator(z), value); + return mapbox::util::apply_visitor(FunctionEvaluator(z), value); } template ::value, int>::type = 0> @@ -146,11 +146,11 @@ void StyleLayer::applyStyleProperty(PropertyKey key, T &target, const float z, c for (AppliedClassProperty &property : applied.properties) { if (now >= property.end) { // We overwrite the current property with the new value. - target = util::apply_visitor(evaluator, property.value); + target = mapbox::util::apply_visitor(evaluator, property.value); } else if (now >= property.begin) { // We overwrite the current property partially with the new value. float progress = float(now - property.begin) / float(property.end - property.begin); - target = interpolate(target, util::apply_visitor(evaluator, property.value), progress); + target = interpolate(target, mapbox::util::apply_visitor(evaluator, property.value), progress); } else { // Do not apply this property because its transition hasn't begun yet. }