Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-24 09:51:26

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
0004 // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
0005 // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
0006 
0007 // This file was modified by Oracle on 2015-2020.
0008 // Modifications copyright (c) 2015-2020, Oracle and/or its affiliates.
0009 
0010 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
0011 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0012 
0013 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
0014 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
0015 
0016 // Use, modification and distribution is subject to the Boost Software License,
0017 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0018 // http://www.boost.org/LICENSE_1_0.txt)
0019 
0020 #ifndef BOOST_GEOMETRY_UTIL_COMPRESS_VARIANT_HPP
0021 #define BOOST_GEOMETRY_UTIL_COMPRESS_VARIANT_HPP
0022 
0023 #include <boost/config/pragma_message.hpp>
0024 #if !defined(BOOST_ALLOW_DEPRECATED_HEADERS)
0025 BOOST_PRAGMA_MESSAGE("This header is deprecated.")
0026 #endif
0027 
0028 #include <boost/mpl/equal_to.hpp>
0029 #include <boost/mpl/fold.hpp>
0030 #include <boost/mpl/front.hpp>
0031 #include <boost/mpl/if.hpp>
0032 #include <boost/mpl/insert.hpp>
0033 #include <boost/mpl/int.hpp>
0034 #include <boost/mpl/set.hpp>
0035 #include <boost/mpl/size.hpp>
0036 #include <boost/mpl/vector.hpp>
0037 #include <boost/variant/variant_fwd.hpp>
0038 
0039 
0040 namespace boost { namespace geometry
0041 {
0042 
0043 
0044 namespace detail
0045 {
0046 
0047 template <typename Variant>
0048 struct unique_types:
0049     boost::mpl::fold<
0050         typename boost::mpl::reverse_fold<
0051             typename Variant::types,
0052             boost::mpl::set<>,
0053             boost::mpl::insert<
0054                 boost::mpl::placeholders::_1,
0055                 boost::mpl::placeholders::_2
0056             >
0057         >::type,
0058         boost::mpl::vector<>,
0059         boost::mpl::push_back
0060             <
0061                 boost::mpl::placeholders::_1, boost::mpl::placeholders::_2
0062             >
0063     >
0064 {};
0065 
0066 template <typename Types>
0067 struct variant_or_single:
0068     boost::mpl::if_<
0069         boost::mpl::equal_to<
0070             boost::mpl::size<Types>,
0071             boost::mpl::int_<1>
0072         >,
0073         typename boost::mpl::front<Types>::type,
0074         typename make_variant_over<Types>::type
0075     >
0076 {};
0077 
0078 } // namespace detail
0079 
0080 
0081 /*!
0082     \brief Meta-function that takes a boost::variant type and tries to minimize
0083         it by doing the following:
0084         - if there's any duplicate types, remove them
0085         - if the result is a variant of one type, turn it into just that type
0086     \ingroup utility
0087     \par Example
0088     \code
0089         typedef variant<int, float, int, long> variant_type;
0090         typedef compress_variant<variant_type>::type compressed;
0091         typedef boost::mpl::vector<int, float, long> result_types;
0092         BOOST_MPL_ASSERT(( boost::mpl::equal<compressed::types, result_types> ));
0093 
0094         typedef variant<int, int, int> one_type_variant_type;
0095         typedef compress_variant<one_type_variant_type>::type single_type;
0096         BOOST_MPL_ASSERT(( boost::equals<single_type, int> ));
0097     \endcode
0098 */
0099 
0100 template <typename Variant>
0101 struct compress_variant:
0102     detail::variant_or_single<
0103         typename detail::unique_types<Variant>::type
0104     >
0105 {};
0106 
0107 
0108 }} // namespace boost::geometry
0109 
0110 
0111 #endif // BOOST_GEOMETRY_UTIL_COMPRESS_VARIANT_HPP