variant - add get<T> overloads where T is stored as recursive_wrapper<T> and avoid directly dealing with recursive_wrapper<T>
This commit is contained in:
parent
ec7f2f3f0c
commit
587437c368
2 changed files with 42 additions and 10 deletions
|
@ -136,7 +136,7 @@ namespace boost { namespace spirit { namespace traits {
|
|||
using type = mapnik::new_geometry::geometry_collection const&;
|
||||
static type pre(mapnik::new_geometry::geometry const& geom)
|
||||
{
|
||||
return mapnik::util::get<mapnik::util::recursive_wrapper<mapnik::new_geometry::geometry_collection>>(geom);
|
||||
return mapnik::util::get<mapnik::new_geometry::geometry_collection>(geom);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2014 Artem Pavlenko
|
||||
* Copyright (C) 2015 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -631,7 +631,8 @@ public:
|
|||
type_index = detail::direct_type<T, Types...>::index;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
// 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)
|
||||
|
@ -640,11 +641,13 @@ public:
|
|||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("in get()");
|
||||
throw std::runtime_error("in get<T>()");
|
||||
}
|
||||
}
|
||||
|
||||
template<typename 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)
|
||||
|
@ -653,7 +656,38 @@ public:
|
|||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("in get()");
|
||||
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>()");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -772,19 +806,17 @@ auto VARIANT_INLINE static apply_visitor(F f, V & v0, V & v1) -> decltype(V::bin
|
|||
|
||||
// getter interface
|
||||
template<typename ResultType, typename T>
|
||||
ResultType & get(T & var)
|
||||
ResultType & get(T & var)
|
||||
{
|
||||
return var.template get<ResultType>();
|
||||
}
|
||||
|
||||
template<typename ResultType, typename T>
|
||||
ResultType const& get(T const& var)
|
||||
ResultType const& get(T const& var)
|
||||
{
|
||||
return var.template get<ResultType>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}}
|
||||
|
||||
#endif // MAPNIK_UTIL_VARIANT_HPP
|
||||
|
|
Loading…
Reference in a new issue