summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Morris <michael.patrick.morris@gmail.com>2015-09-30 16:14:32 -0400
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-09-30 15:34:40 -0700
commitb46c102eb0ec3ca2ff0b422831cb98fa2bdebcba (patch)
tree3525ee2dba9e77fadedda73446a549ac8ebddda5
parent3d57f3ea7c6ae1f098668c37a8c5f79638b0e527 (diff)
downloadqtlocation-mapboxgl-b46c102eb0ec3ca2ff0b422831cb98fa2bdebcba.tar.gz
mason variant@1.0
-rw-r--r--android/mapboxgl-app.gypi1
-rwxr-xr-xconfigure1
-rw-r--r--gyp/core.gypi2
-rw-r--r--gyp/platform-android.gypi1
-rw-r--r--gyp/platform-ios.gypi1
-rw-r--r--include/mbgl/map/camera.hpp3
-rw-r--r--include/mbgl/map/map.hpp2
-rw-r--r--include/mbgl/style/style_properties.hpp3
-rw-r--r--include/mbgl/util/optional.hpp69
-rw-r--r--include/mbgl/util/recursive_wrapper.hpp127
-rw-r--r--include/mbgl/util/variant.hpp793
-rw-r--r--include/mbgl/util/variant_io.hpp41
-rw-r--r--linux/mapboxgl-app.gypi1
-rw-r--r--macosx/mapboxgl-app.gypi1
-rw-r--r--platform/ios/MGLMapView.mm1
-rw-r--r--scripts/android/configure.sh1
-rw-r--r--scripts/ios/configure.sh1
-rw-r--r--scripts/linux/configure.sh1
-rw-r--r--scripts/osx/configure.sh1
-rw-r--r--src/mbgl/annotation/sprite_parser.hpp3
-rw-r--r--src/mbgl/map/geometry_tile.hpp5
-rw-r--r--src/mbgl/map/map.cpp1
-rw-r--r--src/mbgl/map/tile_worker.hpp3
-rw-r--r--src/mbgl/style/filter_expression_private.hpp3
-rw-r--r--src/mbgl/style/function_properties.hpp2
-rw-r--r--src/mbgl/style/property_value.hpp3
-rw-r--r--src/mbgl/style/value.hpp2
m---------src/mbgl/util/geojsonvt0
-rw-r--r--test/test.gypi1
29 files changed, 33 insertions, 1041 deletions
diff --git a/android/mapboxgl-app.gypi b/android/mapboxgl-app.gypi
index 74415df7b4..9789f57aee 100644
--- a/android/mapboxgl-app.gypi
+++ b/android/mapboxgl-app.gypi
@@ -23,6 +23,7 @@
'cflags_cc': [
'<@(boost_cflags)',
+ '<@(variant_cflags)',
],
'libraries': [
'<@(openssl_static_libs)',
diff --git a/configure b/configure
index 6fbaa9f7f8..e91cd86fed 100755
--- a/configure
+++ b/configure
@@ -93,6 +93,7 @@ print_flags libuv static_libs cflags ldflags
print_flags zlib static_libs cflags ldflags
print_flags nunicode static_libs cflags ldflags
print_flags libzip static_libs cflags ldflags
+print_flags variant static_libs cflags ldflags
CONFIG+=" }
}
diff --git a/gyp/core.gypi b/gyp/core.gypi
index f9b361032e..36a03e3b8b 100644
--- a/gyp/core.gypi
+++ b/gyp/core.gypi
@@ -31,10 +31,12 @@
'<@(libuv_cflags)',
'<@(opengl_cflags)',
'<@(boost_cflags)',
+ '<@(variant_cflags)',
],
'cflags': [
'<@(libuv_cflags)',
'<@(opengl_cflags)',
+ '<@(variant_cflags)',
'-fPIC'
],
'ldflags': [
diff --git a/gyp/platform-android.gypi b/gyp/platform-android.gypi
index 41a5733acb..c12c7d2600 100644
--- a/gyp/platform-android.gypi
+++ b/gyp/platform-android.gypi
@@ -27,6 +27,7 @@
'<@(libuv_cflags)',
'<@(nunicode_cflags)',
'<@(boost_cflags)',
+ '<@(variant_cflags)',
],
'ldflags': [
'<@(libpng_ldflags)',
diff --git a/gyp/platform-ios.gypi b/gyp/platform-ios.gypi
index f639051c61..87c4e684c6 100644
--- a/gyp/platform-ios.gypi
+++ b/gyp/platform-ios.gypi
@@ -68,6 +68,7 @@
'cflags_cc': [
'<@(libuv_cflags)',
'<@(boost_cflags)',
+ '<@(variant_cflags)',
],
'libraries': [
'<@(libuv_static_libs)',
diff --git a/include/mbgl/map/camera.hpp b/include/mbgl/map/camera.hpp
index bd0b353bae..a16c1d4dc2 100644
--- a/include/mbgl/map/camera.hpp
+++ b/include/mbgl/map/camera.hpp
@@ -1,8 +1,9 @@
#ifndef MBGL_MAP_CAMERA
#define MBGL_MAP_CAMERA
+#include <mapbox/optional.hpp>
+
#include <mbgl/util/geo.hpp>
-#include <mbgl/util/optional.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/unitbezier.hpp>
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 06695778eb..f60117bb0c 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -2,7 +2,6 @@
#define MBGL_MAP_MAP
#include <mbgl/util/chrono.hpp>
-#include <mbgl/map/camera.hpp>
#include <mbgl/map/update.hpp>
#include <mbgl/map/mode.hpp>
#include <mbgl/util/geo.hpp>
@@ -26,6 +25,7 @@ class SpriteImage;
class Transform;
class PointAnnotation;
class ShapeAnnotation;
+struct CameraOptions;
namespace util {
template <class T> class Thread;
diff --git a/include/mbgl/style/style_properties.hpp b/include/mbgl/style/style_properties.hpp
index 23354b1a24..c0ecc35201 100644
--- a/include/mbgl/style/style_properties.hpp
+++ b/include/mbgl/style/style_properties.hpp
@@ -1,7 +1,8 @@
#ifndef MBGL_STYLE_STYLE_PROPERTIES
#define MBGL_STYLE_STYLE_PROPERTIES
-#include <mbgl/util/variant.hpp>
+#include <mapbox/variant.hpp>
+
#include <mbgl/style/types.hpp>
#include <array>
diff --git a/include/mbgl/util/optional.hpp b/include/mbgl/util/optional.hpp
deleted file mode 100644
index 8d46eae857..0000000000
--- a/include/mbgl/util/optional.hpp
+++ /dev/null
@@ -1,69 +0,0 @@
-#ifndef MAPBOX_UTIL_OPTIONAL_HPP
-#define MAPBOX_UTIL_OPTIONAL_HPP
-
-#include <type_traits>
-
-#include <mbgl/util/variant.hpp>
-
-namespace mapbox
-{
-namespace util
-{
-
-template <typename T> class optional
-{
- static_assert(!std::is_reference<T>::value, "optional doesn't support references");
-
- struct none_type
- {
- };
-
- variant<none_type, T> variant_;
-
- public:
- optional() = default;
-
- optional(optional const &rhs)
- {
- if (this != &rhs)
- { // protect against invalid self-assignment
- variant_ = rhs.variant_;
- }
- }
-
- optional(T const &v) { variant_ = v; }
-
- explicit operator bool() const noexcept { return variant_.template is<T>(); }
-
- T const &get() const { return variant_.template get<T>(); }
- T &get() { return variant_.template get<T>(); }
-
- T const &operator*() const { return this->get(); }
- T operator*() { return this->get(); }
-
- optional &operator=(T const &v)
- {
- variant_ = v;
- return *this;
- }
-
- optional &operator=(optional const &rhs)
- {
- if (this != &rhs)
- {
- variant_ = rhs.variant_;
- }
- return *this;
- }
-
- template <typename... Args> void emplace(Args &&... args)
- {
- variant_ = T{std::forward<Args>(args)...};
- }
-
- void reset() { variant_ = none_type{}; }
-};
-}
-}
-
-#endif
diff --git a/include/mbgl/util/recursive_wrapper.hpp b/include/mbgl/util/recursive_wrapper.hpp
deleted file mode 100644
index 54b27634a3..0000000000
--- a/include/mbgl/util/recursive_wrapper.hpp
+++ /dev/null
@@ -1,127 +0,0 @@
-#ifndef MAPBOX_UTIL_VARIANT_RECURSIVE_WRAPPER_HPP
-#define MAPBOX_UTIL_VARIANT_RECURSIVE_WRAPPER_HPP
-
-#include <utility>
-
-namespace mapbox { namespace util {
-
-template <typename T>
-class recursive_wrapper
-{
-public:
- using type = T;
-private:
-
- T* p_;
-
-public:
-
- ~recursive_wrapper();
- recursive_wrapper();
-
- recursive_wrapper(recursive_wrapper const& operand);
- recursive_wrapper(T const& operand);
- recursive_wrapper(recursive_wrapper&& operand);
- recursive_wrapper(T&& operand);
-
-private:
-
- void assign(const T& rhs);
-
-public:
-
- inline recursive_wrapper& operator=(recursive_wrapper const& rhs)
- {
- assign( rhs.get() );
- return *this;
- }
-
- inline recursive_wrapper& operator=(T const& rhs)
- {
- assign( rhs );
- return *this;
- }
-
- inline void swap(recursive_wrapper& operand) noexcept
- {
- T* temp = operand.p_;
- operand.p_ = p_;
- p_ = temp;
- }
-
-
- recursive_wrapper& operator=(recursive_wrapper&& rhs) noexcept
- {
- swap(rhs);
- return *this;
- }
-
- recursive_wrapper& operator=(T&& rhs)
- {
- get() = std::move(rhs);
- return *this;
- }
-
-
-public:
-
- T& get() { return *get_pointer(); }
- const T& get() const { return *get_pointer(); }
- T* get_pointer() { return p_; }
- const T* get_pointer() const { return p_; }
- operator T const&() const { return this->get(); }
- operator T&() { return this->get(); }
-};
-
-template <typename T>
-recursive_wrapper<T>::~recursive_wrapper()
-{
- delete p_;
-}
-
-template <typename T>
-recursive_wrapper<T>::recursive_wrapper()
- : p_(new T)
-{
-}
-
-template <typename T>
-recursive_wrapper<T>::recursive_wrapper(recursive_wrapper const& operand)
- : p_(new T( operand.get() ))
-{
-}
-
-template <typename T>
-recursive_wrapper<T>::recursive_wrapper(T const& operand)
- : p_(new T(operand))
-{
-}
-
-template <typename T>
-recursive_wrapper<T>::recursive_wrapper(recursive_wrapper&& operand)
- : p_(operand.p_)
-{
- operand.p_ = nullptr;
-}
-
-template <typename T>
-recursive_wrapper<T>::recursive_wrapper(T&& operand)
- : p_(new T( std::move(operand) ))
-{
-}
-
-template <typename T>
-void recursive_wrapper<T>::assign(const T& rhs)
-{
- this->get() = rhs;
-}
-
-template <typename T>
-inline void swap(recursive_wrapper<T>& lhs, recursive_wrapper<T>& rhs) noexcept
-{
- lhs.swap(rhs);
-}
-
-}}
-
-#endif // MAPBOX_UTIL_VARIANT_RECURSIVE_WRAPPER_HPP
diff --git a/include/mbgl/util/variant.hpp b/include/mbgl/util/variant.hpp
deleted file mode 100644
index a3cdea63a7..0000000000
--- a/include/mbgl/util/variant.hpp
+++ /dev/null
@@ -1,793 +0,0 @@
-#ifndef MAPBOX_UTIL_VARIANT_HPP
-#define MAPBOX_UTIL_VARIANT_HPP
-
-#include <utility>
-#include <typeinfo>
-#include <type_traits>
-#include <stdexcept> // runtime_error
-#include <new> // operator new
-#include <cstddef> // size_t
-#include <iosfwd>
-#include <string>
-
-#include "recursive_wrapper.hpp"
-
-#ifdef _MSC_VER
- // http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx
- #ifdef NDEBUG
- #define VARIANT_INLINE __forceinline
- #else
- #define VARIANT_INLINE __declspec(noinline)
- #endif
-#else
- #ifdef NDEBUG
- #define VARIANT_INLINE inline __attribute__((always_inline))
- #else
- #define VARIANT_INLINE __attribute__((noinline))
- #endif
-#endif
-
-#define VARIANT_MAJOR_VERSION 0
-#define VARIANT_MINOR_VERSION 1
-#define VARIANT_PATCH_VERSION 0
-
-// translates to 100
-#define VARIANT_VERSION (VARIANT_MAJOR_VERSION*100000) + (VARIANT_MINOR_VERSION*100) + (VARIANT_PATCH_VERSION)
-
-namespace mapbox { namespace util {
-
-// static visitor
-template <typename R = void>
-struct static_visitor
-{
- using result_type = R;
-protected:
- static_visitor() {}
- ~static_visitor() {}
-};
-
-namespace detail {
-
-static constexpr std::size_t invalid_value = std::size_t(-1);
-
-template <typename T, typename...Types>
-struct direct_type;
-
-template <typename T, typename First, typename...Types>
-struct direct_type<T, First, Types...>
-{
- static constexpr std::size_t index = std::is_same<T, First>::value
- ? sizeof...(Types) : direct_type<T, Types...>::index;
-};
-
-template <typename T>
-struct direct_type<T>
-{
- static constexpr std::size_t index = invalid_value;
-};
-
-template <typename T, typename...Types>
-struct convertible_type;
-
-template <typename T, typename First, typename...Types>
-struct convertible_type<T, First, Types...>
-{
- static constexpr std::size_t index = std::is_convertible<T, First>::value
- ? sizeof...(Types) : convertible_type<T, Types...>::index;
-};
-
-template <typename T>
-struct convertible_type<T>
-{
- static constexpr std::size_t index = invalid_value;
-};
-
-template <typename T, typename...Types>
-struct value_traits
-{
- static constexpr std::size_t direct_index = direct_type<T, Types...>::index;
- static constexpr std::size_t index =
- (direct_index == invalid_value) ? convertible_type<T, Types...>::index : direct_index;
-};
-
-template <typename T, typename...Types>
-struct is_valid_type;
-
-template <typename T, typename First, typename... Types>
-struct is_valid_type<T, First, Types...>
-{
- static constexpr bool value = std::is_convertible<T, First>::value
- || is_valid_type<T, Types...>::value;
-};
-
-template <typename T>
-struct is_valid_type<T> : std::false_type {};
-
-template <std::size_t N, typename ... Types>
-struct select_type
-{
- static_assert(N < sizeof...(Types), "index out of bounds");
-};
-
-template <std::size_t N, typename T, typename ... Types>
-struct select_type<N, T, Types...>
-{
- using type = typename select_type<N - 1, Types...>::type;
-};
-
-template <typename T, typename ... Types>
-struct select_type<0, T, Types...>
-{
- using type = T;
-};
-
-
-template <typename T, typename R = void>
-struct enable_if_type { using type = R; };
-
-template <typename F, typename V, typename Enable = void>
-struct result_of_unary_visit
-{
- using type = typename std::result_of<F(V&)>::type;
-};
-
-template <typename F, typename V>
-struct result_of_unary_visit<F, V, typename enable_if_type<typename F::result_type>::type >
-{
- using type = typename F::result_type;
-};
-
-template <typename F, typename V, class Enable = void>
-struct result_of_binary_visit
-{
- using type = typename std::result_of<F(V&,V&)>::type;
-};
-
-
-template <typename F, typename V>
-struct result_of_binary_visit<F, V, typename enable_if_type<typename F::result_type>::type >
-{
- using type = typename F::result_type;
-};
-
-
-} // namespace detail
-
-
-template <std::size_t arg1, std::size_t ... others>
-struct static_max;
-
-template <std::size_t arg>
-struct static_max<arg>
-{
- static const std::size_t value = arg;
-};
-
-template <std::size_t arg1, std::size_t arg2, std::size_t ... others>
-struct static_max<arg1, arg2, others...>
-{
- static const std::size_t value = arg1 >= arg2 ? static_max<arg1, others...>::value :
- static_max<arg2, others...>::value;
-};
-
-template<typename... Types>
-struct variant_helper;
-
-template<typename T, typename... Types>
-struct variant_helper<T, Types...>
-{
- VARIANT_INLINE static void destroy(const std::size_t id, void * data)
- {
- if (id == sizeof...(Types))
- {
- reinterpret_cast<T*>(data)->~T();
- }
- else
- {
- variant_helper<Types...>::destroy(id, data);
- }
- }
-
- VARIANT_INLINE static void move(const std::size_t old_id, void * old_value, void * new_value)
- {
- if (old_id == sizeof...(Types))
- {
- new (new_value) T(std::move(*reinterpret_cast<T*>(old_value)));
- //std::memcpy(new_value, old_value, sizeof(T));
- // ^^ DANGER: this should only be considered for relocatable types e.g built-in types
- // Also, I don't see any measurable performance benefit just yet
- }
- else
- {
- variant_helper<Types...>::move(old_id, old_value, new_value);
- }
- }
-
- VARIANT_INLINE static void copy(const std::size_t old_id, const void * old_value, void * new_value)
- {
- if (old_id == sizeof...(Types))
- {
- new (new_value) T(*reinterpret_cast<const T*>(old_value));
- }
- else
- {
- variant_helper<Types...>::copy(old_id, old_value, new_value);
- }
- }
-};
-
-template<> struct variant_helper<>
-{
- VARIANT_INLINE static void destroy(const std::size_t, void *) {}
- VARIANT_INLINE static void move(const std::size_t, void *, void *) {}
- VARIANT_INLINE static void copy(const std::size_t, const void *, void *) {}
-};
-
-namespace detail {
-
-template <typename T>
-struct unwrapper
-{
- T const& operator() (T const& obj) const
- {
- return obj;
- }
-
- T& operator() (T & obj) const
- {
- return obj;
- }
-};
-
-
-template <typename T>
-struct unwrapper<recursive_wrapper<T>>
-{
- auto operator() (recursive_wrapper<T> const& obj) const
- -> typename recursive_wrapper<T>::type const&
- {
- return obj.get();
- }
-};
-
-
-template <typename F, typename V, typename R, typename...Types>
-struct dispatcher;
-
-template <typename F, typename V, typename R, typename T, typename...Types>
-struct dispatcher<F, V, R, T, Types...>
-{
- using result_type = R;
- VARIANT_INLINE static result_type apply_const(V const& v, F f)
- {
- if (v.get_type_index() == sizeof...(Types))
- {
- return f(unwrapper<T>()(v. template get<T>()));
- }
- else
- {
- return dispatcher<F, V, R, Types...>::apply_const(v, f);
- }
- }
-
- VARIANT_INLINE static result_type apply(V & v, F f)
- {
- if (v.get_type_index() == sizeof...(Types))
- {
- return f(unwrapper<T>()(v. template get<T>()));
- }
- else
- {
- return dispatcher<F, V, R, Types...>::apply(v, f);
- }
- }
-};
-
-template<typename F, typename V, typename R>
-struct dispatcher<F, V, R>
-{
- using result_type = R;
- VARIANT_INLINE static result_type apply_const(V const&, F)
- {
- throw std::runtime_error(std::string("unary dispatch: FAIL ") + typeid(V).name());
- }
-
- VARIANT_INLINE static result_type apply(V &, F)
- {
- throw std::runtime_error(std::string("unary dispatch: FAIL ") + typeid(V).name());
- }
-};
-
-
-template <typename F, typename V, typename R, typename T, typename...Types>
-struct binary_dispatcher_rhs;
-
-template <typename F, typename V, typename R, typename T0, typename T1, typename...Types>
-struct binary_dispatcher_rhs<F, V, R, T0, T1, Types...>
-{
- using result_type = R;
- VARIANT_INLINE static result_type apply_const(V const& lhs, V const& rhs, F f)
- {
- if (rhs.get_type_index() == sizeof...(Types)) // call binary functor
- {
- return f(unwrapper<T0>()(lhs. template get<T0>()),
- unwrapper<T1>()(rhs. template get<T1>()));
- }
- else
- {
- return binary_dispatcher_rhs<F, V, R, T0, Types...>::apply_const(lhs, rhs, f);
- }
- }
-
- VARIANT_INLINE static result_type apply(V & lhs, V & rhs, F f)
- {
- if (rhs.get_type_index() == sizeof...(Types)) // call binary functor
- {
- return f(unwrapper<T0>()(lhs. template get<T0>()),
- unwrapper<T1>()(rhs. template get<T1>()));
- }
- else
- {
- return binary_dispatcher_rhs<F, V, R, T0, Types...>::apply(lhs, rhs, f);
- }
- }
-
-};
-
-template<typename F, typename V, typename R, typename T>
-struct binary_dispatcher_rhs<F, V, R, T>
-{
- using result_type = R;
- VARIANT_INLINE static result_type apply_const(V const&, V const&, F)
- {
- throw std::runtime_error("binary dispatch: FAIL");
- }
- VARIANT_INLINE static result_type apply(V &, V &, F)
- {
- throw std::runtime_error("binary dispatch: FAIL");
- }
-};
-
-
-template <typename F, typename V, typename R, typename T, typename...Types>
-struct binary_dispatcher_lhs;
-
-template <typename F, typename V, typename R, typename T0, typename T1, typename...Types>
-struct binary_dispatcher_lhs<F, V, R, T0, T1, Types...>
-{
- using result_type = R;
- VARIANT_INLINE static result_type apply_const(V const& lhs, V const& rhs, F f)
- {
- if (lhs.get_type_index() == sizeof...(Types)) // call binary functor
- {
- return f(lhs. template get<T1>(), rhs. template get<T0>());
- }
- else
- {
- return binary_dispatcher_lhs<F, V, R, T0, Types...>::apply_const(lhs, rhs, f);
- }
- }
-
- VARIANT_INLINE static result_type apply(V & lhs, V & rhs, F f)
- {
- if (lhs.get_type_index() == sizeof...(Types)) // call binary functor
- {
- return f(lhs. template get<T1>(), rhs. template get<T0>());
- }
- else
- {
- return binary_dispatcher_lhs<F, V, R, T0, Types...>::apply(lhs, rhs, f);
- }
- }
-
-};
-
-template<typename F, typename V, typename R, typename T>
-struct binary_dispatcher_lhs<F, V, R, T>
-{
- using result_type = R;
- VARIANT_INLINE static result_type apply_const(V const&, V const&, F)
- {
- throw std::runtime_error("binary dispatch: FAIL");
- }
-
- VARIANT_INLINE static result_type apply(V &, V &, F)
- {
- throw std::runtime_error("binary dispatch: FAIL");
- }
-};
-
-template <typename F, typename V, typename R, typename...Types>
-struct binary_dispatcher;
-
-template <typename F, typename V, typename R, typename T, typename...Types>
-struct binary_dispatcher<F, V, R, T, Types...>
-{
- using result_type = R;
- VARIANT_INLINE static result_type apply_const(V const& v0, V const& v1, F f)
- {
- if (v0.get_type_index() == sizeof...(Types))
- {
- if (v0.get_type_index() == v1.get_type_index())
- {
- return f(v0. template get<T>(), v1. template get<T>()); // call binary functor
- }
- else
- {
- return binary_dispatcher_rhs<F, V, R, T, Types...>::apply_const(v0, v1, f);
- }
- }
- else if (v1.get_type_index() == sizeof...(Types))
- {
- return binary_dispatcher_lhs<F, V, R, T, Types...>::apply_const(v0, v1, f);
- }
- return binary_dispatcher<F, V, R, Types...>::apply_const(v0, v1, f);
- }
-
- VARIANT_INLINE static result_type apply(V & v0, V & v1, F f)
- {
- if (v0.get_type_index() == sizeof...(Types))
- {
- if (v0.get_type_index() == v1.get_type_index())
- {
- return f(v0. template get<T>(), v1. template get<T>()); // call binary functor
- }
- else
- {
- return binary_dispatcher_rhs<F, V, R, T, Types...>::apply(v0, v1, f);
- }
- }
- else if (v1.get_type_index() == sizeof...(Types))
- {
- return binary_dispatcher_lhs<F, V, R, T, Types...>::apply(v0, v1, f);
- }
- return binary_dispatcher<F, V, R, Types...>::apply(v0, v1, f);
- }
-};
-
-template<typename F, typename V, typename R>
-struct binary_dispatcher<F, V, R>
-{
- using result_type = R;
- VARIANT_INLINE static result_type apply_const(V const&, V const&, F)
- {
- throw std::runtime_error("binary dispatch: FAIL");
- }
-
- VARIANT_INLINE static result_type apply(V &, V &, F)
- {
- throw std::runtime_error("binary dispatch: FAIL");
- }
-};
-
-// comparator functors
-struct equal_comp
-{
- template <typename T>
- bool operator()(T const& lhs, T const& rhs) const
- {
- return lhs == rhs;
- }
-};
-
-struct less_comp
-{
- template <typename T>
- bool operator()(T const& lhs, T const& rhs) const
- {
- return lhs < rhs;
- }
-};
-
-template <typename Variant, typename Comp>
-class comparer
-{
-public:
- explicit comparer(Variant const& lhs) noexcept
- : lhs_(lhs) {}
- comparer& operator=(comparer const&) = delete;
- // visitor
- template<typename T>
- bool operator()(T const& rhs_content) const
- {
- T const& lhs_content = lhs_.template get<T>();
- return Comp()(lhs_content, rhs_content);
- }
-private:
- Variant const& lhs_;
-};
-
-
-} // namespace detail
-
-struct no_init {};
-
-template<typename... Types>
-class variant
-{
-private:
-
- static const std::size_t data_size = static_max<sizeof(Types)...>::value;
- static const std::size_t data_align = static_max<alignof(Types)...>::value;
-
- using data_type = typename std::aligned_storage<data_size, data_align>::type;
- using helper_type = variant_helper<Types...>;
-
- std::size_t type_index;
- data_type data;
-
-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) {}
-
- // http://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers
- template <typename T, class = typename std::enable_if<
- detail::is_valid_type<typename std::remove_reference<T>::type, Types...>::value>::type>
- VARIANT_INLINE variant(T && val) noexcept
- : type_index(detail::value_traits<typename std::remove_reference<T>::type, Types...>::index)
- {
- constexpr std::size_t index = sizeof...(Types) - detail::value_traits<typename std::remove_reference<T>::type, Types...>::index - 1;
- using target_type = typename detail::select_type<index, Types...>::type;
- new (&data) target_type(std::forward<T>(val)); // nothrow
- }
-
- VARIANT_INLINE variant(variant<Types...> const& old)
- : type_index(old.type_index)
- {
- helper_type::copy(old.type_index, &old.data, &data);
- }
-
- VARIANT_INLINE variant(variant<Types...>&& old) noexcept
- : type_index(old.type_index)
- {
- helper_type::move(old.type_index, &old.data, &data);
- }
-
- friend void swap(variant<Types...> & first, variant<Types...> & second)
- {
- using std::swap; //enable ADL
- swap(first.type_index, second.type_index);
- swap(first.data, second.data);
- }
-
- VARIANT_INLINE variant<Types...>& operator=(variant<Types...> other)
- {
- swap(*this, other);
- return *this;
- }
-
- // conversions
- // move-assign
- template <typename T>
- VARIANT_INLINE variant<Types...>& operator=(T && rhs) noexcept
- {
- variant<Types...> temp(std::forward<T>(rhs));
- swap(*this, temp);
- return *this;
- }
-
- // copy-assign
- template <typename T>
- VARIANT_INLINE variant<Types...>& operator=(T const& rhs)
- {
- variant<Types...> temp(rhs);
- swap(*this, temp);
- return *this;
- }
-
- template<typename T>
- VARIANT_INLINE bool is() const
- {
- return (type_index == detail::direct_type<T, Types...>::index);
- }
-
- VARIANT_INLINE bool valid() const
- {
- return (type_index != detail::invalid_value);
- }
-
- template<typename T, typename... Args>
- VARIANT_INLINE void set(Args&&... args)
- {
- helper_type::destroy(type_index, &data);
- new (&data) T(std::forward<Args>(args)...);
- type_index = detail::direct_type<T, Types...>::index;
- }
-
- // get<T>()
- template<typename T, typename std::enable_if<(detail::direct_type<T, Types...>::index != detail::invalid_value)>::type* = nullptr>
- VARIANT_INLINE T& get()
- {
- if (type_index == detail::direct_type<T, Types...>::index)
- {
- return *reinterpret_cast<T*>(&data);
- }
- else
- {
- throw std::runtime_error("in get<T>()");
- }
- }
-
- template <typename T, typename std::enable_if<
- (detail::direct_type<T, Types...>::index != detail::invalid_value)
- >::type* = nullptr>
- VARIANT_INLINE T const& get() const
- {
- if (type_index == detail::direct_type<T, Types...>::index)
- {
- return *reinterpret_cast<T const*>(&data);
- }
- else
- {
- throw std::runtime_error("in get<T>()");
- }
- }
-
- // get<T>() - T stored as recursive_wrapper<T>
- template <typename T, typename std::enable_if<
- (detail::direct_type<recursive_wrapper<T>, Types...>::index != detail::invalid_value)
- >::type* = nullptr>
- VARIANT_INLINE T& get()
- {
- if (type_index == detail::direct_type<recursive_wrapper<T>, Types...>::index)
- {
- return (*reinterpret_cast<recursive_wrapper<T>*>(&data)).get();
- }
- else
- {
- throw std::runtime_error("in get<T>()");
- }
- }
-
- template <typename T,typename std::enable_if<
- (detail::direct_type<recursive_wrapper<T>, Types...>::index != detail::invalid_value)
- >::type* = nullptr>
- VARIANT_INLINE T const& get() const
- {
- if (type_index == detail::direct_type<recursive_wrapper<T>, Types...>::index)
- {
- return (*reinterpret_cast<recursive_wrapper<T> const*>(&data)).get();
- }
- else
- {
- throw std::runtime_error("in get<T>()");
- }
- }
- VARIANT_INLINE std::size_t get_type_index() const
- {
- return type_index;
- }
-
- VARIANT_INLINE int which() const noexcept
- {
- return static_cast<int>(sizeof...(Types) - type_index - 1);
- }
-
- // visitor
- // unary
- template <typename F, typename V>
- auto VARIANT_INLINE
- static visit(V const& v, F f)
- -> decltype(detail::dispatcher<F, V,
- typename detail::result_of_unary_visit<F,
- typename detail::select_type<0, Types...>::type>::type, Types...>::apply_const(v, f))
- {
- using R = typename detail::result_of_unary_visit<F, typename detail::select_type<0, Types...>::type>::type;
- return detail::dispatcher<F, V, R, Types...>::apply_const(v, f);
- }
- // non-const
- template <typename F, typename V>
- auto VARIANT_INLINE
- static visit(V & v, F f)
- -> decltype(detail::dispatcher<F, V,
- typename detail::result_of_unary_visit<F,
- typename detail::select_type<0, Types...>::type>::type, Types...>::apply(v, f))
- {
- using R = typename detail::result_of_unary_visit<F, typename detail::select_type<0, Types...>::type>::type;
- return detail::dispatcher<F, V, R, Types...>::apply(v, f);
- }
-
- // binary
- // const
- template <typename F, typename V>
- auto VARIANT_INLINE
- static binary_visit(V const& v0, V const& v1, F f)
- -> decltype(detail::binary_dispatcher<F, V,
- typename detail::result_of_binary_visit<F,
- typename detail::select_type<0, Types...>::type>::type, Types...>::apply_const(v0, v1, f))
- {
- using R = typename detail::result_of_binary_visit<F,typename detail::select_type<0, Types...>::type>::type;
- return detail::binary_dispatcher<F, V, R, Types...>::apply_const(v0, v1, f);
- }
- // non-const
- template <typename F, typename V>
- auto VARIANT_INLINE
- static binary_visit(V& v0, V& v1, F f)
- -> decltype(detail::binary_dispatcher<F, V,
- typename detail::result_of_binary_visit<F,
- typename detail::select_type<0, Types...>::type>::type, Types...>::apply(v0, v1, f))
- {
- using R = typename detail::result_of_binary_visit<F,typename detail::select_type<0, Types...>::type>::type;
- return detail::binary_dispatcher<F, V, R, Types...>::apply(v0, v1, f);
- }
-
- ~variant() noexcept
- {
- helper_type::destroy(type_index, &data);
- }
-
- // comparison operators
- // equality
- VARIANT_INLINE bool operator==(variant const& rhs) const
- {
- if (this->get_type_index() != rhs.get_type_index())
- return false;
- detail::comparer<variant, detail::equal_comp> visitor(*this);
- return visit(rhs, visitor);
- }
- // less than
- VARIANT_INLINE bool operator<(variant const& rhs) const
- {
- if (this->get_type_index() != rhs.get_type_index())
- {
- return this->get_type_index() < rhs.get_type_index();
- // ^^ borrowed from boost::variant
- }
- detail::comparer<variant, detail::less_comp> visitor(*this);
- return visit(rhs, visitor);
- }
-};
-
-// unary visitor interface
-
-// const
-template <typename V, typename F>
-auto VARIANT_INLINE static apply_visitor(F f, V const& v) -> decltype(V::visit(v, f))
-{
- return V::visit(v, f);
-}
-// non-const
-template <typename V, typename F>
-auto VARIANT_INLINE static apply_visitor(F f, V & v) -> decltype(V::visit(v, f))
-{
- return V::visit(v, f);
-}
-
-// binary visitor interface
-// const
-template <typename V, typename F>
-auto VARIANT_INLINE static apply_visitor(F f, V const& v0, V const& v1) -> decltype(V::binary_visit(v0, v1, f))
-{
- return V::binary_visit(v0, v1, f);
-}
-// non-const
-template <typename V, typename F>
-auto VARIANT_INLINE static apply_visitor(F f, V & v0, V & v1) -> decltype(V::binary_visit(v0, v1, f))
-{
- return V::binary_visit(v0, v1, f);
-}
-
-// getter interface
-template<typename ResultType, typename T>
-ResultType & get(T & var)
-{
- return var.template get<ResultType>();
-}
-
-template<typename ResultType, typename T>
-ResultType const& get(T const& var)
-{
- return var.template get<ResultType>();
-}
-
-
-}}
-
-#endif // MAPBOX_UTIL_VARIANT_HPP
diff --git a/include/mbgl/util/variant_io.hpp b/include/mbgl/util/variant_io.hpp
deleted file mode 100644
index 224732d97c..0000000000
--- a/include/mbgl/util/variant_io.hpp
+++ /dev/null
@@ -1,41 +0,0 @@
-#ifndef MAPBOX_UTIL_VARIANT_IO_HPP
-#define MAPBOX_UTIL_VARIANT_IO_HPP
-
-#include "variant.hpp"
-
-namespace mapbox { namespace util {
-
-namespace detail {
-// operator<< helper
-template <typename Out>
-class printer
-{
-public:
- explicit printer(Out & out)
- : out_(out) {}
- printer& operator=(printer const&) = delete;
-
-// visitor
- template <typename T>
- void operator()(T const& operand) const
- {
- out_ << operand;
- }
-private:
- Out & out_;
-};
-}
-
-// operator<<
-template <typename charT, typename traits, typename... Types>
-VARIANT_INLINE std::basic_ostream<charT, traits>&
-operator<< (std::basic_ostream<charT, traits>& out, variant<Types...> const& rhs)
-{
- detail::printer<std::basic_ostream<charT, traits>> visitor(out);
- apply_visitor(visitor, rhs);
- return out;
-}
-
-}}
-
-#endif //MAPBOX_UTIL_VARIANT_IO_HPP
diff --git a/linux/mapboxgl-app.gypi b/linux/mapboxgl-app.gypi
index 8457c2ce78..20218171d0 100644
--- a/linux/mapboxgl-app.gypi
+++ b/linux/mapboxgl-app.gypi
@@ -32,6 +32,7 @@
'<@(opengl_cflags)',
'<@(boost_cflags)',
'<@(glfw_cflags)',
+ '<@(variant_cflags)',
],
'ldflags': [
'<@(glfw_ldflags)',
diff --git a/macosx/mapboxgl-app.gypi b/macosx/mapboxgl-app.gypi
index e1d9476e1d..a8925c3d66 100644
--- a/macosx/mapboxgl-app.gypi
+++ b/macosx/mapboxgl-app.gypi
@@ -36,6 +36,7 @@
'cflags_cc': [
'<@(boost_cflags)',
'<@(glfw_cflags)',
+ '<@(variant_cflags)',
],
'ldflags': [
'-framework SystemConfiguration', # For NSUserDefaults and Reachability
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index a2f67c7bba..0a42f8f5f7 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -11,6 +11,7 @@
#include <mbgl/annotation/point_annotation.hpp>
#include <mbgl/annotation/shape_annotation.hpp>
#include <mbgl/annotation/sprite_image.hpp>
+#include <mbgl/map/camera.hpp>
#include <mbgl/platform/platform.hpp>
#include <mbgl/platform/darwin/reachability.h>
#include <mbgl/storage/sqlite_cache.hpp>
diff --git a/scripts/android/configure.sh b/scripts/android/configure.sh
index 5e5a9034c1..8255ce0eea 100644
--- a/scripts/android/configure.sh
+++ b/scripts/android/configure.sh
@@ -10,5 +10,6 @@ LIBUV_VERSION=1.4.0
ZLIB_VERSION=system
NUNICODE_VERSION=1.5.1
LIBZIP_VERSION=0.11.2
+VARIANT_VERSION=1.0
export MASON_ANDROID_ABI=${MASON_PLATFORM_VERSION}
diff --git a/scripts/ios/configure.sh b/scripts/ios/configure.sh
index 0562e0e39a..0cf1664b73 100644
--- a/scripts/ios/configure.sh
+++ b/scripts/ios/configure.sh
@@ -4,3 +4,4 @@ BOOST_VERSION=1.57.0
SQLITE_VERSION=system
LIBUV_VERSION=0.10.28
ZLIB_VERSION=system
+VARIANT_VERSION=1.0
diff --git a/scripts/linux/configure.sh b/scripts/linux/configure.sh
index 1099a65504..843428aa34 100644
--- a/scripts/linux/configure.sh
+++ b/scripts/linux/configure.sh
@@ -11,6 +11,7 @@ LIBUV_VERSION=0.10.28
ZLIB_VERSION=system
NUNICODE_VERSION=1.5.1
LIBZIP_VERSION=0.11.2
+VARIANT_VERSION=1.0
function print_opengl_flags {
CONFIG+=" 'opengl_cflags%': $(quote_flags $(pkg-config gl x11 --cflags)),"$LN
diff --git a/scripts/osx/configure.sh b/scripts/osx/configure.sh
index fc3c5f464f..3f43bfd31c 100644
--- a/scripts/osx/configure.sh
+++ b/scripts/osx/configure.sh
@@ -11,3 +11,4 @@ LIBUV_VERSION=0.10.28
ZLIB_VERSION=system
NUNICODE_VERSION=1.5.1
LIBZIP_VERSION=0.11.2
+VARIANT_VERSION=1.0
diff --git a/src/mbgl/annotation/sprite_parser.hpp b/src/mbgl/annotation/sprite_parser.hpp
index d7e9953359..c5856ebbc7 100644
--- a/src/mbgl/annotation/sprite_parser.hpp
+++ b/src/mbgl/annotation/sprite_parser.hpp
@@ -1,9 +1,10 @@
#ifndef MBGL_ANNOTATIONS_SPRITE_PARSER
#define MBGL_ANNOTATIONS_SPRITE_PARSER
+#include <mapbox/variant.hpp>
+
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/geo.hpp>
-#include <mbgl/util/variant.hpp>
#include <string>
#include <memory>
diff --git a/src/mbgl/map/geometry_tile.hpp b/src/mbgl/map/geometry_tile.hpp
index dc1ef10725..37d7bf1427 100644
--- a/src/mbgl/map/geometry_tile.hpp
+++ b/src/mbgl/map/geometry_tile.hpp
@@ -1,10 +1,11 @@
#ifndef MBGL_MAP_GEOMETRY_TILE
#define MBGL_MAP_GEOMETRY_TILE
+#include <mapbox/variant.hpp>
+#include <mapbox/optional.hpp>
+
#include <mbgl/style/value.hpp>
-#include <mbgl/util/optional.hpp>
#include <mbgl/util/ptr.hpp>
-#include <mbgl/util/variant.hpp>
#include <mbgl/util/vec.hpp>
#include <mbgl/util/noncopyable.hpp>
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 4ba8d6cd8f..50819f66a7 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -1,5 +1,6 @@
#include <mbgl/map/map.hpp>
#include <mbgl/map/map_context.hpp>
+#include <mbgl/map/camera.hpp>
#include <mbgl/map/view.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/map/transform_state.hpp>
diff --git a/src/mbgl/map/tile_worker.hpp b/src/mbgl/map/tile_worker.hpp
index 62527b9fd9..b045ae0f6e 100644
--- a/src/mbgl/map/tile_worker.hpp
+++ b/src/mbgl/map/tile_worker.hpp
@@ -1,7 +1,8 @@
#ifndef MBGL_MAP_TILE_WORKER
#define MBGL_MAP_TILE_WORKER
-#include <mbgl/util/variant.hpp>
+#include <mapbox/variant.hpp>
+
#include <mbgl/map/tile_data.hpp>
#include <mbgl/geometry/elements_buffer.hpp>
#include <mbgl/geometry/fill_buffer.hpp>
diff --git a/src/mbgl/style/filter_expression_private.hpp b/src/mbgl/style/filter_expression_private.hpp
index 381f8f617c..ff6301b7c6 100644
--- a/src/mbgl/style/filter_expression_private.hpp
+++ b/src/mbgl/style/filter_expression_private.hpp
@@ -1,4 +1,5 @@
-#include <mbgl/util/optional.hpp>
+#include <mapbox/optional.hpp>
+
#include <mbgl/style/value_comparison.hpp>
namespace mbgl {
diff --git a/src/mbgl/style/function_properties.hpp b/src/mbgl/style/function_properties.hpp
index 924f192330..c41918a0fb 100644
--- a/src/mbgl/style/function_properties.hpp
+++ b/src/mbgl/style/function_properties.hpp
@@ -1,7 +1,7 @@
#ifndef MBGL_STYLE_FUNCTION_PROPERTIES
#define MBGL_STYLE_FUNCTION_PROPERTIES
-#include <mbgl/util/variant.hpp>
+#include <mapbox/variant.hpp>
#include <vector>
diff --git a/src/mbgl/style/property_value.hpp b/src/mbgl/style/property_value.hpp
index fbc3f3bd6a..f225899c66 100644
--- a/src/mbgl/style/property_value.hpp
+++ b/src/mbgl/style/property_value.hpp
@@ -1,7 +1,8 @@
#ifndef MBGL_STYLE_PROPERTY_VALUE
#define MBGL_STYLE_PROPERTY_VALUE
-#include <mbgl/util/variant.hpp>
+#include <mapbox/variant.hpp>
+
#include <mbgl/style/function_properties.hpp>
#include <mbgl/style/piecewisefunction_properties.hpp>
#include <mbgl/style/types.hpp>
diff --git a/src/mbgl/style/value.hpp b/src/mbgl/style/value.hpp
index 8b0b21c20c..4649134b20 100644
--- a/src/mbgl/style/value.hpp
+++ b/src/mbgl/style/value.hpp
@@ -1,7 +1,7 @@
#ifndef MBGL_STYLE_VALUE
#define MBGL_STYLE_VALUE
-#include <mbgl/util/variant.hpp>
+#include <mapbox/variant.hpp>
#include <rapidjson/document.h>
#include <cstdlib>
diff --git a/src/mbgl/util/geojsonvt b/src/mbgl/util/geojsonvt
-Subproject 995ffc72c556da4b4880a6036fbcf7159fc5ecc
+Subproject 83bffbcc6ad75ff59c7640036567820c8932161
diff --git a/test/test.gypi b/test/test.gypi
index a35b00133b..1e3e2e0901 100644
--- a/test/test.gypi
+++ b/test/test.gypi
@@ -102,6 +102,7 @@
'<@(opengl_cflags)',
'<@(boost_cflags)',
'<@(sqlite_cflags)',
+ '<@(variant_cflags)',
],
'ldflags': [
'<@(libuv_ldflags)',