Chris@102
|
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
|
Chris@102
|
2
|
Chris@102
|
3 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
|
Chris@102
|
4 // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
|
Chris@102
|
5 // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
|
Chris@102
|
6
|
Chris@102
|
7 // This file was modified by Oracle on 2015.
|
Chris@102
|
8 // Modifications copyright (c) 2015, Oracle and/or its affiliates.
|
Chris@102
|
9
|
Chris@102
|
10 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
|
Chris@102
|
11
|
Chris@102
|
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
Chris@102
|
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
Chris@102
|
14
|
Chris@102
|
15 // Use, modification and distribution is subject to the Boost Software License,
|
Chris@102
|
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@102
|
17 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
18
|
Chris@102
|
19 #ifndef BOOST_GEOMETRY_UTIL_COMPRESS_VARIANT_HPP
|
Chris@102
|
20 #define BOOST_GEOMETRY_UTIL_COMPRESS_VARIANT_HPP
|
Chris@102
|
21
|
Chris@102
|
22
|
Chris@102
|
23 #include <boost/mpl/equal_to.hpp>
|
Chris@102
|
24 #include <boost/mpl/fold.hpp>
|
Chris@102
|
25 #include <boost/mpl/front.hpp>
|
Chris@102
|
26 #include <boost/mpl/if.hpp>
|
Chris@102
|
27 #include <boost/mpl/insert.hpp>
|
Chris@102
|
28 #include <boost/mpl/int.hpp>
|
Chris@102
|
29 #include <boost/mpl/set.hpp>
|
Chris@102
|
30 #include <boost/mpl/size.hpp>
|
Chris@102
|
31 #include <boost/mpl/vector.hpp>
|
Chris@102
|
32 #include <boost/variant/variant_fwd.hpp>
|
Chris@102
|
33
|
Chris@102
|
34
|
Chris@102
|
35 namespace boost { namespace geometry
|
Chris@102
|
36 {
|
Chris@102
|
37
|
Chris@102
|
38
|
Chris@102
|
39 namespace detail
|
Chris@102
|
40 {
|
Chris@102
|
41
|
Chris@102
|
42 template <typename Variant>
|
Chris@102
|
43 struct unique_types:
|
Chris@102
|
44 boost::mpl::fold<
|
Chris@102
|
45 typename boost::mpl::reverse_fold<
|
Chris@102
|
46 typename Variant::types,
|
Chris@102
|
47 boost::mpl::set<>,
|
Chris@102
|
48 boost::mpl::insert<
|
Chris@102
|
49 boost::mpl::placeholders::_1,
|
Chris@102
|
50 boost::mpl::placeholders::_2
|
Chris@102
|
51 >
|
Chris@102
|
52 >::type,
|
Chris@102
|
53 boost::mpl::vector<>,
|
Chris@102
|
54 boost::mpl::push_back
|
Chris@102
|
55 <
|
Chris@102
|
56 boost::mpl::placeholders::_1, boost::mpl::placeholders::_2
|
Chris@102
|
57 >
|
Chris@102
|
58 >
|
Chris@102
|
59 {};
|
Chris@102
|
60
|
Chris@102
|
61 template <typename Types>
|
Chris@102
|
62 struct variant_or_single:
|
Chris@102
|
63 boost::mpl::if_<
|
Chris@102
|
64 boost::mpl::equal_to<
|
Chris@102
|
65 boost::mpl::size<Types>,
|
Chris@102
|
66 boost::mpl::int_<1>
|
Chris@102
|
67 >,
|
Chris@102
|
68 typename boost::mpl::front<Types>::type,
|
Chris@102
|
69 typename make_variant_over<Types>::type
|
Chris@102
|
70 >
|
Chris@102
|
71 {};
|
Chris@102
|
72
|
Chris@102
|
73 } // namespace detail
|
Chris@102
|
74
|
Chris@102
|
75
|
Chris@102
|
76 /*!
|
Chris@102
|
77 \brief Meta-function that takes a boost::variant type and tries to minimize
|
Chris@102
|
78 it by doing the following:
|
Chris@102
|
79 - if there's any duplicate types, remove them
|
Chris@102
|
80 - if the result is a variant of one type, turn it into just that type
|
Chris@102
|
81 \ingroup utility
|
Chris@102
|
82 \par Example
|
Chris@102
|
83 \code
|
Chris@102
|
84 typedef variant<int, float, int, long> variant_type;
|
Chris@102
|
85 typedef compress_variant<variant_type>::type compressed;
|
Chris@102
|
86 typedef boost::mpl::vector<int, float, long> result_types;
|
Chris@102
|
87 BOOST_MPL_ASSERT(( boost::mpl::equal<compressed::types, result_types> ));
|
Chris@102
|
88
|
Chris@102
|
89 typedef variant<int, int, int> one_type_variant_type;
|
Chris@102
|
90 typedef compress_variant<one_type_variant_type>::type single_type;
|
Chris@102
|
91 BOOST_MPL_ASSERT(( boost::equals<single_type, int> ));
|
Chris@102
|
92 \endcode
|
Chris@102
|
93 */
|
Chris@102
|
94
|
Chris@102
|
95 template <typename Variant>
|
Chris@102
|
96 struct compress_variant:
|
Chris@102
|
97 detail::variant_or_single<
|
Chris@102
|
98 typename detail::unique_types<Variant>::type
|
Chris@102
|
99 >
|
Chris@102
|
100 {};
|
Chris@102
|
101
|
Chris@102
|
102
|
Chris@102
|
103 }} // namespace boost::geometry
|
Chris@102
|
104
|
Chris@102
|
105
|
Chris@102
|
106 #endif // BOOST_GEOMETRY_UTIL_COMPRESS_VARIANT_HPP
|