diff --git a/include/mapnik/util/variant.hpp b/include/mapnik/util/variant.hpp index 2c4806e27..90dd624ce 100644 --- a/include/mapnik/util/variant.hpp +++ b/include/mapnik/util/variant.hpp @@ -276,6 +276,15 @@ struct unwrapper> } }; +template +struct unwrapper> +{ + auto operator() (std::reference_wrapper const& obj) const + -> typename recursive_wrapper::type const& + { + return obj.get(); + } +}; template struct dispatcher; @@ -693,6 +702,37 @@ public: } } + // get() - T stored as std::reference_wrapper + template , Types...>::index != detail::invalid_value) + >::type* = nullptr> + VARIANT_INLINE T& get() + { + if (type_index == detail::direct_type, Types...>::index) + { + return (*reinterpret_cast*>(&data)).get(); + } + else + { + throw std::runtime_error("in get()"); + } + } + + template , Types...>::index != detail::invalid_value) + >::type* = nullptr> + VARIANT_INLINE T const& get() const + { + if (type_index == detail::direct_type, Types...>::index) + { + return (*reinterpret_cast const*>(&data)).get(); + } + else + { + throw std::runtime_error("in get()"); + } + } + VARIANT_INLINE std::size_t get_type_index() const { return type_index;