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