std_array.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. #include <boost/config.hpp>
  11. #ifndef BOOST_NO_CXX11_HDR_ARRAY
  12. #define BOOST_GEOMETRY_ADAPTED_STD_ARRAY_TAG_DEFINED
  13. #include <cstddef>
  14. #include <boost/type_traits/is_arithmetic.hpp>
  15. #include <boost/geometry/core/access.hpp>
  16. #include <boost/geometry/core/cs.hpp>
  17. #include <boost/geometry/core/coordinate_dimension.hpp>
  18. #include <boost/geometry/core/coordinate_type.hpp>
  19. #include <boost/geometry/core/tags.hpp>
  20. #include <array>
  21. namespace boost { namespace geometry
  22. {
  23. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  24. namespace traits
  25. {
  26. #ifndef DOXYGEN_NO_DETAIL
  27. namespace detail
  28. {
  29. // Create class and specialization to indicate the tag
  30. // for normal cases and the case that the type of the std-array is arithmetic
  31. template <bool>
  32. struct std_array_tag
  33. {
  34. typedef geometry_not_recognized_tag type;
  35. };
  36. template <>
  37. struct std_array_tag<true>
  38. {
  39. typedef point_tag type;
  40. };
  41. } // namespace detail
  42. #endif // DOXYGEN_NO_DETAIL
  43. // Assign the point-tag, preventing arrays of points getting a point-tag
  44. template <typename CoordinateType, std::size_t DimensionCount>
  45. struct tag<std::array<CoordinateType, DimensionCount> >
  46. : detail::std_array_tag<boost::is_arithmetic<CoordinateType>::value> {};
  47. template <typename CoordinateType, std::size_t DimensionCount>
  48. struct coordinate_type<std::array<CoordinateType, DimensionCount> >
  49. {
  50. typedef CoordinateType type;
  51. };
  52. template <typename CoordinateType, std::size_t DimensionCount>
  53. struct dimension<std::array<CoordinateType, DimensionCount> >: boost::mpl::int_<DimensionCount> {};
  54. template <typename CoordinateType, std::size_t DimensionCount, std::size_t Dimension>
  55. struct access<std::array<CoordinateType, DimensionCount>, Dimension>
  56. {
  57. static inline CoordinateType get(std::array<CoordinateType, DimensionCount> const& a)
  58. {
  59. return a[Dimension];
  60. }
  61. static inline void set(std::array<CoordinateType, DimensionCount>& a,
  62. CoordinateType const& value)
  63. {
  64. a[Dimension] = value;
  65. }
  66. };
  67. } // namespace traits
  68. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  69. }} // namespace boost::geometry
  70. #define BOOST_GEOMETRY_REGISTER_STD_ARRAY_CS(CoordinateSystem) \
  71. namespace boost { namespace geometry { namespace traits { \
  72. template <class T, std::size_t N> \
  73. struct coordinate_system<std::array<T, N> > \
  74. { \
  75. typedef CoordinateSystem type; \
  76. }; \
  77. }}}
  78. #else
  79. #warning "This file requires compiler and library support for the ISO C++ 2011 standard."
  80. #endif // BOOST_NO_CXX11_HDR_ARRAY
  81. #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_ARRAY_HPP