select_sequence_element.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Boost.Geometry
  2. // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
  3. // Use, modification and distribution is subject to the Boost Software License,
  4. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_GEOMETRY_UTIL_SELECT_SEQUENCE_ELEMENT
  7. #define BOOST_GEOMETRY_UTIL_SELECT_SEQUENCE_ELEMENT
  8. #include <boost/mpl/if.hpp>
  9. #include <boost/mpl/int.hpp>
  10. #include <boost/mpl/at.hpp>
  11. #include <boost/mpl/size.hpp>
  12. #include <boost/type_traits/is_same.hpp>
  13. #include <boost/geometry/core/coordinate_type.hpp>
  14. #include <boost/geometry/util/select_most_precise.hpp>
  15. namespace boost { namespace geometry
  16. {
  17. namespace util
  18. {
  19. template <typename Curr, typename Next>
  20. struct pred_more_precise_coordinate_type
  21. {
  22. typedef typename geometry::coordinate_type<Curr>::type curr_coord_t;
  23. typedef typename geometry::coordinate_type<Next>::type next_coord_t;
  24. typedef typename boost::mpl::if_c
  25. <
  26. boost::is_same
  27. <
  28. curr_coord_t,
  29. typename select_most_precise
  30. <
  31. curr_coord_t,
  32. next_coord_t
  33. >::type
  34. >::value,
  35. Curr,
  36. Next
  37. >::type type;
  38. };
  39. template
  40. <
  41. typename Seq,
  42. template<typename, typename> class Pred = pred_more_precise_coordinate_type,
  43. int I = 0,
  44. int N = boost::mpl::size<Seq>::value
  45. >
  46. struct select_sequence_element
  47. {
  48. typedef typename boost::mpl::at<Seq, boost::mpl::int_<I> >::type curr_t;
  49. typedef typename select_sequence_element<Seq, Pred, I+1, N>::type next_t;
  50. typedef typename Pred<curr_t, next_t>::type type;
  51. };
  52. template <typename Seq, template<typename, typename> class Pred, int N>
  53. struct select_sequence_element<Seq, Pred, N, N>
  54. {
  55. typedef typename boost::mpl::at<Seq, boost::mpl::int_<N-1> >::type type;
  56. };
  57. } // namespace util
  58. }} // namespace boost::geometry
  59. #endif // BOOST_GEOMETRY_UTIL_SELECT_SEQUENCE_ELEMENT