From d147e18153910d4f21eaece75e06725b1249c8f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 19 Aug 2014 11:38:26 +0200 Subject: update mapbox/variant --- include/mbgl/util/variant.hpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'include/mbgl/util/variant.hpp') diff --git a/include/mbgl/util/variant.hpp b/include/mbgl/util/variant.hpp index ddc82ee311..1eca5160c7 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); -- cgit v1.2.1