meta.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Boost.Geometry Index
  2. //
  3. // Copyright (c) 2011-2019 Adam Wulkiewicz, Lodz, Poland.
  4. //
  5. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #include <boost/range.hpp>
  9. #include <boost/mpl/aux_/has_type.hpp>
  10. #include <boost/mpl/if.hpp>
  11. #include <boost/mpl/and.hpp>
  12. #include <boost/type_traits/is_convertible.hpp>
  13. #include <boost/type_traits/is_same.hpp>
  14. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_META_HPP
  15. #define BOOST_GEOMETRY_INDEX_DETAIL_META_HPP
  16. namespace boost { namespace geometry { namespace index { namespace detail {
  17. template <typename T>
  18. struct is_range
  19. : ::boost::mpl::aux::has_type< ::boost::range_iterator<T> >
  20. {};
  21. //template <typename T, typename V, bool IsRange>
  22. //struct is_range_of_convertible_values_impl
  23. // : ::boost::is_convertible<typename ::boost::range_value<T>::type, V>
  24. //{};
  25. //
  26. //template <typename T, typename V>
  27. //struct is_range_of_convertible_values_impl<T, V, false>
  28. // : ::boost::mpl::bool_<false>
  29. //{};
  30. //
  31. //template <typename T, typename V>
  32. //struct is_range_of_convertible_values
  33. // : is_range_of_convertible_values_impl<T, V, is_range<T>::value>
  34. //{};
  35. // Implemented this way in order to prevent instantiation of all type traits at
  36. // once because some of them are causing problems with gcc 4.6 namely
  37. // is_convertible<bg::model::segment<>, std::pair<bg::model::segment<>, T> >
  38. // because segment<> is derived from pair<> and pair<> has copy ctor taking
  39. // other pair<> of any types the compiler tries to instantiate ctor of
  40. // pair<segment, T> taking pair<point, point> which results in instantiation of
  41. // segment's ctor taking a point which results in compilation error.
  42. // This is probably compiler's bug.
  43. template <typename T, typename Value, typename Indexable, typename ResultType, int Ver>
  44. struct convertible_type_impl
  45. {
  46. typedef ResultType type;
  47. };
  48. template <typename T, typename Value, typename Indexable>
  49. struct convertible_type_impl<T, Value, Indexable, void, 0>
  50. {
  51. typedef typename boost::mpl::if_c
  52. <
  53. boost::is_convertible<T, Indexable>::value,
  54. Indexable,
  55. void
  56. >::type result_type;
  57. typedef typename convertible_type_impl
  58. <
  59. T, Value, Indexable, result_type, 1
  60. >::type type;
  61. };
  62. template <typename T, typename Value, typename Indexable>
  63. struct convertible_type_impl<T, Value, Indexable, void, 1>
  64. {
  65. typedef typename boost::mpl::if_c
  66. <
  67. boost::is_convertible<T, Value>::value,
  68. Value,
  69. void
  70. >::type type;
  71. };
  72. template <typename T, typename Value, typename Indexable>
  73. struct convertible_type
  74. {
  75. typedef typename boost::mpl::if_c
  76. <
  77. boost::is_same<T, Value>::value,
  78. Value,
  79. typename boost::mpl::if_c
  80. <
  81. boost::is_same<T, Indexable>::value,
  82. Indexable,
  83. void
  84. >::type
  85. >::type result_type;
  86. typedef typename convertible_type_impl
  87. <
  88. T, Value, Indexable, result_type, 0
  89. >::type type;
  90. };
  91. }}}} // namespace boost::geometry::index::detail
  92. #endif // BOOST_GEOMETRY_INDEX_DETAIL_META_HPP