From a9e5f267c33e5cb803885d2f33cf91b6735eee66 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Sun, 6 Jun 2021 16:38:05 +0200 Subject: [PATCH] Move std::array from base class to member of box_view and segment_view. --- include/boost/geometry/views/box_view.hpp | 44 ++++++++++--------- include/boost/geometry/views/segment_view.hpp | 40 +++++++++-------- 2 files changed, 44 insertions(+), 40 deletions(-) diff --git a/include/boost/geometry/views/box_view.hpp b/include/boost/geometry/views/box_view.hpp index ecb049163..634af89c8 100644 --- a/include/boost/geometry/views/box_view.hpp +++ b/include/boost/geometry/views/box_view.hpp @@ -30,6 +30,19 @@ namespace boost { namespace geometry { +// NOTE: This is equivalent to the previous implementation with detail::points_view. +// Technically this should not be called a view because it owns the elements. +// It's also not a borrowed_range because of dangling iterators after the +// destruction. +// It's a container or more specifically a ring of some sort, e.g. static_ring. +// NOTE: It would be possible to implement a borrowed_range or a view. +// The iterators would have to store copies of points. +// Another possibility is to store the original Box or reference/pointer +// to Box and index. But then the reference would be the value type +// so technically they would be InputIterators not RandomAccessIterators. +// NOTE: This object can not represent a Box correctly in all coordinates systems. +// It's correct only in cartesian CS so maybe it should be removed entirely. + /*! \brief Makes a box behave like a ring or a range @@ -49,35 +62,24 @@ namespace boost { namespace geometry */ template struct box_view - // NOTE: This is equivalent to the previous implementation with detail::points_view - // Technically this should not be called a view because it owns the elements. - // It's also not a borrowed_range because of dangling iterators after the - // destruction. - // It's a container or more specifically a ring of some sort, - // e.g. static_ring. - // NOTE: It would be possible to implement a borrowed_range or a view. - // The iterators would have to store copies of points. - // Another possibility is to store the original Box or reference/pointer - // to Box and index. But then the reference would be the value type - // so technically they would be InputIterators not RandomAccessIterators. - // NOTE: This object can not represent a Box correctly in all coordinates systems. - // It's correct only in cartesian CS so maybe it should be removed entirely. - : private std::array::type, 5> { - using base_t = std::array::type, 5>; + using array_t = std::array::type, 5>; - using iterator = typename base_t::const_iterator; - using const_iterator = typename base_t::const_iterator; + using iterator = typename array_t::const_iterator; + using const_iterator = typename array_t::const_iterator; /// Constructor accepting the box to adapt explicit box_view(Box const& box) { - detail::assign_box_corners_oriented(box, static_cast(*this)); - (*this)[4] = (*this)[0]; + detail::assign_box_corners_oriented(box, m_array); + m_array[4] = m_array[0]; } - const_iterator begin() const noexcept { return base_t::begin(); } - const_iterator end() const noexcept { return base_t::end(); } + const_iterator begin() const noexcept { return m_array.begin(); } + const_iterator end() const noexcept { return m_array.end(); } + +private: + array_t m_array; }; diff --git a/include/boost/geometry/views/segment_view.hpp b/include/boost/geometry/views/segment_view.hpp index e16424305..07dffe590 100644 --- a/include/boost/geometry/views/segment_view.hpp +++ b/include/boost/geometry/views/segment_view.hpp @@ -29,6 +29,17 @@ namespace boost { namespace geometry { +// NOTE: This is equivalent to the previous implementation with detail::points_view. +// Technically this should not be called a view because it owns the elements. +// It's also not a borrowed_range because of dangling iterators after the +// destruction. +// It's a container or more specifically a linestring of some sort, e.g. static_linestring. +// NOTE: It would be possible to implement a borrowed_range or a view. +// The iterators would have to store copies of points. +// Another possibility is to store the original Segment or reference/pointer +// to Segment and index. But then the reference would be the value type +// so technically they would be InputIterators not RandomAccessIterators. + /*! \brief Makes a segment behave like a linestring or a range @@ -47,33 +58,24 @@ namespace boost { namespace geometry */ template struct segment_view - // NOTE: This is equivalent to the previous implementation with detail::points_view - // Technically this should not be called a view because it owns the elements. - // It's also not a borrowed_range because of dangling iterators after the - // destruction. - // It's a container or more specifically a linestring of some sort, - // e.g. static_linestring. - // NOTE: It would be possible to implement a borrowed_range or a view. - // The iterators would have to store copies of points. - // Another possibility is to store the original Segment or reference/pointer - // to Segment and index. But then the reference would be the value type - // so technically they would be InputIterators not RandomAccessIterators. - : private std::array::type, 2> { - using base_t = std::array::type, 2>; + using array_t = std::array::type, 2>; - using iterator = typename base_t::const_iterator; - using const_iterator = typename base_t::const_iterator; + using iterator = typename array_t::const_iterator; + using const_iterator = typename array_t::const_iterator; /// Constructor accepting the segment to adapt explicit segment_view(Segment const& segment) { - geometry::detail::assign_point_from_index<0>(segment, (*this)[0]); - geometry::detail::assign_point_from_index<1>(segment, (*this)[1]); + geometry::detail::assign_point_from_index<0>(segment, m_array[0]); + geometry::detail::assign_point_from_index<1>(segment, m_array[1]); } - const_iterator begin() const noexcept { return base_t::begin(); } - const_iterator end() const noexcept { return base_t::end(); } + const_iterator begin() const noexcept { return m_array.begin(); } + const_iterator end() const noexcept { return m_array.end(); } + +private: + array_t m_array; };