1 // Boost.Geometry (aka GGL, Generic Geometry Library) 2 3 // Copyright (c) 2014-2015 Samuel Debionne, Grenoble, France. 4 5 // This file was modified by Oracle on 2015. 6 // Modifications copyright (c) 2015, Oracle and/or its affiliates. 7 8 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle 9 10 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library 11 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. 12 13 // Use, modification and distribution is subject to the Boost Software License, 14 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 15 // http://www.boost.org/LICENSE_1_0.txt) 16 17 #ifndef BOOST_GEOMETRY_UTIL_COMBINE_IF_HPP 18 #define BOOST_GEOMETRY_UTIL_COMBINE_IF_HPP 19 20 #include <boost/mpl/fold.hpp> 21 #include <boost/mpl/if.hpp> 22 #include <boost/mpl/bind.hpp> 23 #include <boost/mpl/set.hpp> 24 #include <boost/mpl/insert.hpp> 25 #include <boost/mpl/placeholders.hpp> 26 27 28 namespace boost { namespace geometry 29 { 30 31 namespace util 32 { 33 34 35 /*! 36 \brief Meta-function to generate all the combination of pairs of types 37 from a given sequence Sequence except those that does not satisfy the 38 predicate Pred 39 \ingroup utility 40 \par Example 41 \code 42 typedef boost::mpl::vector<boost::mpl::int_<0>, boost::mpl::int_<1> > types; 43 typedef combine_if<types, types, always<true_> >::type combinations; 44 typedef boost::mpl::vector< 45 pair<boost::mpl::int_<1>, boost::mpl::int_<1> >, 46 pair<boost::mpl::int_<1>, boost::mpl::int_<0> >, 47 pair<boost::mpl::int_<0>, boost::mpl::int_<1> >, 48 pair<boost::mpl::int_<0>, boost::mpl::int_<0> > 49 > result_types; 50 51 BOOST_MPL_ASSERT(( boost::mpl::equal<combinations, result_types> )); 52 \endcode 53 */ 54 template <typename Sequence1, typename Sequence2, typename Pred> 55 struct combine_if 56 { 57 struct combine 58 { 59 template <typename Result, typename T> 60 struct apply 61 { 62 typedef typename boost::mpl::fold<Sequence2, Result, 63 boost::mpl::if_ 64 < 65 boost::mpl::bind 66 < 67 typename boost::mpl::lambda<Pred>::type, 68 T, 69 boost::mpl::_2 70 >, 71 boost::mpl::insert 72 < 73 boost::mpl::_1, boost::mpl::pair<T, boost::mpl::_2> 74 >, 75 boost::mpl::_1 76 > 77 >::type type; 78 }; 79 }; 80 81 typedef typename boost::mpl::fold 82 < 83 Sequence1, boost::mpl::set0<>, combine 84 >::type type; 85 }; 86 87 88 } // namespace util 89 90 }} // namespace boost::geometry 91 92 #endif // BOOST_GEOMETRY_UTIL_COMBINE_IF_HPP 93