std_array.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2010 Alfredo Correa
  3. // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2016 Norbert Wenzel
  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. #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_ARRAY_HPP
  9. #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_ARRAY_HPP
  10. #define BOOST_GEOMETRY_ADAPTED_STD_ARRAY_TAG_DEFINED
  11. #include <cstddef>
  12. #include <boost/type_traits/is_arithmetic.hpp>
  13. #include <boost/geometry/core/access.hpp>
  14. #include <boost/geometry/core/cs.hpp>
  15. #include <boost/geometry/core/coordinate_dimension.hpp>
  16. #include <boost/geometry/core/coordinate_type.hpp>
  17. #include <boost/geometry/core/tags.hpp>
  18. #include <array>
  19. namespace boost { namespace geometry
  20. {
  21. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  22. namespace traits
  23. {
  24. #ifndef DOXYGEN_NO_DETAIL
  25. namespace detail
  26. {
  27. // Create class and specialization to indicate the tag
  28. // for normal cases and the case that the type of the std-array is arithmetic
  29. template <bool>
  30. struct std_array_tag
  31. {
  32. typedef geometry_not_recognized_tag type;
  33. };
  34. template <>
  35. struct std_array_tag<true>
  36. {
  37. typedef point_tag type;
  38. };
  39. } // namespace detail
  40. #endif // DOXYGEN_NO_DETAIL
  41. // Assign the point-tag, preventing arrays of points getting a point-tag
  42. template <typename CoordinateType, std::size_t DimensionCount>
  43. struct tag<std::array<CoordinateType, DimensionCount> >
  44. : detail::std_array_tag<boost::is_arithmetic<CoordinateType>::value> {};
  45. template <typename CoordinateType, std::size_t DimensionCount>
  46. struct coordinate_type<std::array<CoordinateType, DimensionCount> >
  47. {
  48. typedef CoordinateType type;
  49. };
  50. template <typename CoordinateType, std::size_t DimensionCount>
  51. struct dimension<std::array<CoordinateType, DimensionCount> >: boost::mpl::int_<DimensionCount> {};
  52. template <typename CoordinateType, std::size_t DimensionCount, std::size_t Dimension>
  53. struct access<std::array<CoordinateType, DimensionCount>, Dimension>
  54. {
  55. static inline CoordinateType get(std::array<CoordinateType, DimensionCount> const& a)
  56. {
  57. return a[Dimension];
  58. }
  59. static inline void set(std::array<CoordinateType, DimensionCount>& a,
  60. CoordinateType const& value)
  61. {
  62. a[Dimension] = value;
  63. }
  64. };
  65. } // namespace traits
  66. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  67. }} // namespace boost::geometry
  68. #define BOOST_GEOMETRY_REGISTER_STD_ARRAY_CS(CoordinateSystem) \
  69. namespace boost { namespace geometry { namespace traits { \
  70. template <class T, std::size_t N> \
  71. struct coordinate_system<std::array<T, N> > \
  72. { \
  73. typedef CoordinateSystem type; \
  74. }; \
  75. }}}
  76. #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_ARRAY_HPP