combine_if.hpp 2.9 KB

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