std_array.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. // This file was modified by Oracle on 2020.
  6. // Modifications copyright (c) 2020, Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_ARRAY_HPP
  12. #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_ARRAY_HPP
  13. #include <boost/config.hpp>
  14. #define BOOST_GEOMETRY_ADAPTED_STD_ARRAY_TAG_DEFINED
  15. #include <array>
  16. #include <cstddef>
  17. #include <type_traits>
  18. #include <boost/geometry/core/access.hpp>
  19. #include <boost/geometry/core/cs.hpp>
  20. #include <boost/geometry/core/coordinate_dimension.hpp>
  21. #include <boost/geometry/core/coordinate_type.hpp>
  22. #include <boost/geometry/core/tags.hpp>
  23. namespace boost { namespace geometry
  24. {
  25. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  26. namespace traits
  27. {
  28. #ifndef DOXYGEN_NO_DETAIL
  29. namespace detail
  30. {
  31. // Create class and specialization to indicate the tag
  32. // for normal cases and the case that the type of the std-array is arithmetic
  33. template <bool>
  34. struct std_array_tag
  35. {
  36. typedef geometry_not_recognized_tag type;
  37. };
  38. template <>
  39. struct std_array_tag<true>
  40. {
  41. typedef point_tag type;
  42. };
  43. } // namespace detail
  44. #endif // DOXYGEN_NO_DETAIL
  45. // Assign the point-tag, preventing arrays of points getting a point-tag
  46. template <typename CoordinateType, std::size_t DimensionCount>
  47. struct tag<std::array<CoordinateType, DimensionCount> >
  48. : detail::std_array_tag<std::is_arithmetic<CoordinateType>::value> {};
  49. template <typename CoordinateType, std::size_t DimensionCount>
  50. struct coordinate_type<std::array<CoordinateType, DimensionCount> >
  51. {
  52. typedef CoordinateType type;
  53. };
  54. template <typename CoordinateType, std::size_t DimensionCount>
  55. struct dimension<std::array<CoordinateType, DimensionCount> >
  56. : std::integral_constant<std::size_t, DimensionCount>
  57. {};
  58. template <typename CoordinateType, std::size_t DimensionCount, std::size_t Dimension>
  59. struct access<std::array<CoordinateType, DimensionCount>, Dimension>
  60. {
  61. static inline CoordinateType get(std::array<CoordinateType, DimensionCount> const& a)
  62. {
  63. return a[Dimension];
  64. }
  65. static inline void set(std::array<CoordinateType, DimensionCount>& a,
  66. CoordinateType const& value)
  67. {
  68. a[Dimension] = value;
  69. }
  70. };
  71. } // namespace traits
  72. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  73. }} // namespace boost::geometry
  74. #define BOOST_GEOMETRY_REGISTER_STD_ARRAY_CS(CoordinateSystem) \
  75. namespace boost { namespace geometry { namespace traits { \
  76. template <class T, std::size_t N> \
  77. struct coordinate_system<std::array<T, N> > \
  78. { \
  79. typedef CoordinateSystem type; \
  80. }; \
  81. }}}
  82. #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_ARRAY_HPP