std_array.hpp 3.2 KB

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