combine_if.hpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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-2020.
  4. // Modifications copyright (c) 2015-2020, 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/config/pragma_message.hpp>
  15. #if !defined(BOOST_ALLOW_DEPRECATED_HEADERS)
  16. BOOST_PRAGMA_MESSAGE("This header is deprecated.")
  17. #endif
  18. #include <boost/mpl/bind.hpp>
  19. #include <boost/mpl/fold.hpp>
  20. #include <boost/mpl/if.hpp>
  21. #include <boost/mpl/insert.hpp>
  22. #include <boost/mpl/pair.hpp>
  23. #include <boost/mpl/placeholders.hpp>
  24. #include <boost/mpl/set.hpp>
  25. namespace boost { namespace geometry
  26. {
  27. namespace util
  28. {
  29. /*!
  30. \brief Meta-function to generate all the combination of pairs of types
  31. from a given sequence Sequence except those that does not satisfy the
  32. predicate Pred
  33. \ingroup utility
  34. \par Example
  35. \code
  36. typedef boost::mpl::vector<boost::mpl::int_<0>, boost::mpl::int_<1> > types;
  37. typedef combine_if<types, types, always<true_> >::type combinations;
  38. typedef boost::mpl::vector<
  39. pair<boost::mpl::int_<1>, boost::mpl::int_<1> >,
  40. pair<boost::mpl::int_<1>, boost::mpl::int_<0> >,
  41. pair<boost::mpl::int_<0>, boost::mpl::int_<1> >,
  42. pair<boost::mpl::int_<0>, boost::mpl::int_<0> >
  43. > result_types;
  44. BOOST_MPL_ASSERT(( boost::mpl::equal<combinations, result_types> ));
  45. \endcode
  46. */
  47. template <typename Sequence1, typename Sequence2, typename Pred>
  48. struct combine_if
  49. {
  50. struct combine
  51. {
  52. template <typename Result, typename T>
  53. struct apply
  54. {
  55. typedef typename boost::mpl::fold<Sequence2, Result,
  56. boost::mpl::if_
  57. <
  58. boost::mpl::bind
  59. <
  60. typename boost::mpl::lambda<Pred>::type,
  61. T,
  62. boost::mpl::_2
  63. >,
  64. boost::mpl::insert
  65. <
  66. boost::mpl::_1, boost::mpl::pair<T, boost::mpl::_2>
  67. >,
  68. boost::mpl::_1
  69. >
  70. >::type type;
  71. };
  72. };
  73. typedef typename boost::mpl::fold
  74. <
  75. Sequence1, boost::mpl::set0<>, combine
  76. >::type type;
  77. };
  78. } // namespace util
  79. }} // namespace boost::geometry
  80. #endif // BOOST_GEOMETRY_UTIL_COMBINE_IF_HPP