Chris@102: // Boost.Geometry (aka GGL, Generic Geometry Library) Chris@102: Chris@102: // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. Chris@102: // Copyright (c) 2008-2015 Bruno Lalande, Paris, France. Chris@102: // Copyright (c) 2009-2015 Mateusz Loskot, London, UK. Chris@102: Chris@102: // This file was modified by Oracle on 2015. Chris@102: // Modifications copyright (c) 2015, Oracle and/or its affiliates. Chris@102: Chris@102: // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle Chris@102: Chris@102: // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library Chris@102: // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. Chris@102: Chris@102: // Use, modification and distribution is subject to the Boost Software License, Chris@102: // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@102: // http://www.boost.org/LICENSE_1_0.txt) Chris@102: Chris@102: #ifndef BOOST_GEOMETRY_UTIL_COMPRESS_VARIANT_HPP Chris@102: #define BOOST_GEOMETRY_UTIL_COMPRESS_VARIANT_HPP Chris@102: Chris@102: Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: Chris@102: Chris@102: namespace boost { namespace geometry Chris@102: { Chris@102: Chris@102: Chris@102: namespace detail Chris@102: { Chris@102: Chris@102: template Chris@102: struct unique_types: Chris@102: boost::mpl::fold< Chris@102: typename boost::mpl::reverse_fold< Chris@102: typename Variant::types, Chris@102: boost::mpl::set<>, Chris@102: boost::mpl::insert< Chris@102: boost::mpl::placeholders::_1, Chris@102: boost::mpl::placeholders::_2 Chris@102: > Chris@102: >::type, Chris@102: boost::mpl::vector<>, Chris@102: boost::mpl::push_back Chris@102: < Chris@102: boost::mpl::placeholders::_1, boost::mpl::placeholders::_2 Chris@102: > Chris@102: > Chris@102: {}; Chris@102: Chris@102: template Chris@102: struct variant_or_single: Chris@102: boost::mpl::if_< Chris@102: boost::mpl::equal_to< Chris@102: boost::mpl::size, Chris@102: boost::mpl::int_<1> Chris@102: >, Chris@102: typename boost::mpl::front::type, Chris@102: typename make_variant_over::type Chris@102: > Chris@102: {}; Chris@102: Chris@102: } // namespace detail Chris@102: Chris@102: Chris@102: /*! Chris@102: \brief Meta-function that takes a boost::variant type and tries to minimize Chris@102: it by doing the following: Chris@102: - if there's any duplicate types, remove them Chris@102: - if the result is a variant of one type, turn it into just that type Chris@102: \ingroup utility Chris@102: \par Example Chris@102: \code Chris@102: typedef variant variant_type; Chris@102: typedef compress_variant::type compressed; Chris@102: typedef boost::mpl::vector result_types; Chris@102: BOOST_MPL_ASSERT(( boost::mpl::equal )); Chris@102: Chris@102: typedef variant one_type_variant_type; Chris@102: typedef compress_variant::type single_type; Chris@102: BOOST_MPL_ASSERT(( boost::equals )); Chris@102: \endcode Chris@102: */ Chris@102: Chris@102: template Chris@102: struct compress_variant: Chris@102: detail::variant_or_single< Chris@102: typename detail::unique_types::type Chris@102: > Chris@102: {}; Chris@102: Chris@102: Chris@102: }} // namespace boost::geometry Chris@102: Chris@102: Chris@102: #endif // BOOST_GEOMETRY_UTIL_COMPRESS_VARIANT_HPP