From 00f00369cd3d5780a405ebbc26dee07d5f1d034b Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Thu, 3 Sep 2020 16:26:06 +0200 Subject: [PATCH] Replace add_const_if_c with transcribe_const. Move add_const_if_c to util/type_traits.hpp Remove usage when not needed. --- .../geometry/algorithms/detail/as_range.hpp | 26 +++++------ .../algorithms/detail/for_each_range.hpp | 14 +++--- .../boost/geometry/algorithms/for_each.hpp | 15 +++--- include/boost/geometry/core/exterior_ring.hpp | 7 +-- .../extensions/views/section_view.hpp | 12 ++--- .../boost/geometry/util/add_const_if_c.hpp | 38 ++------------- .../geometry/util/for_each_coordinate.hpp | 46 +++++++------------ include/boost/geometry/util/readme.txt | 17 ------- include/boost/geometry/util/type_traits.hpp | 43 +++++++++++++++++ 9 files changed, 96 insertions(+), 122 deletions(-) delete mode 100644 include/boost/geometry/util/readme.txt diff --git a/include/boost/geometry/algorithms/detail/as_range.hpp b/include/boost/geometry/algorithms/detail/as_range.hpp index fef5156ee..1d45c5e9d 100644 --- a/include/boost/geometry/algorithms/detail/as_range.hpp +++ b/include/boost/geometry/algorithms/detail/as_range.hpp @@ -4,6 +4,10 @@ // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +// This file was modified by Oracle on 2020. +// Modifications copyright (c) 2020 Oracle and/or its affiliates. +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. @@ -19,8 +23,6 @@ #include #include -#include - namespace boost { namespace geometry { @@ -31,22 +33,20 @@ namespace dispatch { -template +template struct as_range { - static inline typename add_const_if_c::type& get( - typename add_const_if_c::type& input) + static inline Range& get(Geometry& input) { return input; } }; -template -struct as_range +template +struct as_range { - static inline typename add_const_if_c::type& get( - typename add_const_if_c::type& input) + static inline Range& get(Geometry& input) { return exterior_ring(input); } @@ -73,8 +73,7 @@ inline Range& as_range(Geometry& input) < typename tag::type, Geometry, - Range, - false + Range >::get(input); } @@ -91,9 +90,8 @@ inline Range const& as_range(Geometry const& input) return dispatch::as_range < typename tag::type, - Geometry, - Range, - true + Geometry const, + Range const >::get(input); } diff --git a/include/boost/geometry/algorithms/detail/for_each_range.hpp b/include/boost/geometry/algorithms/detail/for_each_range.hpp index 4638b8395..c8885d167 100644 --- a/include/boost/geometry/algorithms/detail/for_each_range.hpp +++ b/include/boost/geometry/algorithms/detail/for_each_range.hpp @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include @@ -195,11 +195,11 @@ struct for_each_range Geometry, detail::for_each::fe_range_range < - typename add_const_if_c + detail::transcribe_const_t < - std::is_const::value, + Geometry, typename boost::range_value::type - >::type + > > > {}; @@ -212,11 +212,11 @@ struct for_each_range Geometry, detail::for_each::fe_range_polygon < - typename add_const_if_c + detail::transcribe_const_t < - std::is_const::value, + Geometry, typename boost::range_value::type - >::type + > > > {}; diff --git a/include/boost/geometry/algorithms/for_each.hpp b/include/boost/geometry/algorithms/for_each.hpp index 946626b8b..273604ca5 100644 --- a/include/boost/geometry/algorithms/for_each.hpp +++ b/include/boost/geometry/algorithms/for_each.hpp @@ -23,7 +23,6 @@ #include -#include #include @@ -40,8 +39,8 @@ #include -#include #include +#include #include @@ -108,21 +107,21 @@ struct fe_segment_segment template struct fe_range_value { - typedef typename add_const_if_c + typedef detail::transcribe_const_t < - std::is_const::value, + Range, typename boost::range_value::type - >::type type; + > type; }; template struct fe_point_type { - typedef typename add_const_if_c + typedef detail::transcribe_const_t < - std::is_const::value, + Range, typename point_type::type - >::type type; + > type; }; diff --git a/include/boost/geometry/core/exterior_ring.hpp b/include/boost/geometry/core/exterior_ring.hpp index 46425c2a0..4b0377b26 100644 --- a/include/boost/geometry/core/exterior_ring.hpp +++ b/include/boost/geometry/core/exterior_ring.hpp @@ -27,7 +27,6 @@ #include #include #include -#include namespace boost { namespace geometry @@ -83,11 +82,7 @@ struct exterior_ring { static typename geometry::ring_return_type::type - apply(typename add_const_if_c - < - std::is_const::type::value, - Polygon - >::type& polygon) + apply(Polygon& polygon) { return traits::exterior_ring < diff --git a/include/boost/geometry/extensions/views/section_view.hpp b/include/boost/geometry/extensions/views/section_view.hpp index 8e0dcce50..126e2b4c0 100644 --- a/include/boost/geometry/extensions/views/section_view.hpp +++ b/include/boost/geometry/extensions/views/section_view.hpp @@ -4,6 +4,10 @@ // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +// This file was modified by Oracle on 2020. +// Modifications copyright (c) 2020, Oracle and/or its affiliates. +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. @@ -20,7 +24,7 @@ #include #include -#include +#include namespace boost { namespace geometry @@ -55,11 +59,7 @@ private : // Might be replaced declaring as BOOST_AUTO typedef typename boost::range_iterator < - typename add_const_if_c - < - boost::is_const::value, - range_type - >::type + detail::transcribe_const_t >::type iterator_type; iterator_type m_begin, m_end; diff --git a/include/boost/geometry/util/add_const_if_c.hpp b/include/boost/geometry/util/add_const_if_c.hpp index eed4b9cb4..51639d0ba 100644 --- a/include/boost/geometry/util/add_const_if_c.hpp +++ b/include/boost/geometry/util/add_const_if_c.hpp @@ -19,42 +19,10 @@ #define BOOST_GEOMETRY_UTIL_ADD_CONST_IF_C_HPP -#include +#include +BOOST_HEADER_DEPRECATED("") - -namespace boost { namespace geometry -{ - - -/*! - \brief Meta-function to define a const or non const type - \ingroup utility - \details If the boolean template parameter is true, the type parameter - will be defined as const, otherwise it will be defined as it was. - This meta-function is used to have one implementation for both - const and non const references - \note This traits class is completely independant from Boost.Geometry - and might be a separate addition to Boost - \note Used in a.o. for_each, interior_rings, exterior_ring - \par Example - \code - void foo(typename add_const_if_c::type& point) - \endcode -*/ -template -struct add_const_if_c -{ - typedef std::conditional_t - < - IsConst, - Type const, - Type - > type; -}; - - - -}} // namespace boost::geometry +#include #endif // BOOST_GEOMETRY_UTIL_ADD_CONST_IF_C_HPP diff --git a/include/boost/geometry/util/for_each_coordinate.hpp b/include/boost/geometry/util/for_each_coordinate.hpp index fb1e31856..4dfd11395 100644 --- a/include/boost/geometry/util/for_each_coordinate.hpp +++ b/include/boost/geometry/util/for_each_coordinate.hpp @@ -4,6 +4,10 @@ // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +// This file was modified by Oracle on 2020. +// Modifications copyright (c) 2020, Oracle and/or its affiliates. +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. @@ -16,7 +20,6 @@ #include #include -#include namespace boost { namespace geometry { @@ -25,36 +28,31 @@ namespace boost { namespace geometry namespace detail { -template +template +< + typename Point, + int Dimension = 0, + int DimensionCount = dimension::value +> struct coordinates_scanner { template - static inline Op apply(typename add_const_if_c - < - IsConst, - Point - >::type& point, Op operation) + static inline Op apply(Point& point, Op operation) { operation.template apply(point); return coordinates_scanner < Point, - Dimension+1, - DimensionCount, - IsConst + Dimension + 1 >::apply(point, operation); } }; -template -struct coordinates_scanner +template +struct coordinates_scanner { template - static inline Op apply(typename add_const_if_c - < - IsConst, - Point - >::type& , Op operation) + static inline Op apply(Point& , Op operation) { return operation; } @@ -68,12 +66,7 @@ inline void for_each_coordinate(Point& point, Op operation) { BOOST_CONCEPT_ASSERT( (concepts::Point) ); - typedef typename detail::coordinates_scanner - < - Point, 0, dimension::type::value, false - > scanner; - - scanner::apply(point, operation); + detail::coordinates_scanner::apply(point, operation); } template @@ -81,12 +74,7 @@ inline Op for_each_coordinate(Point const& point, Op operation) { BOOST_CONCEPT_ASSERT( (concepts::ConstPoint) ); - typedef typename detail::coordinates_scanner - < - Point, 0, dimension::type::value, true - > scanner; - - return scanner::apply(point, operation); + return detail::coordinates_scanner::apply(point, operation); } }} // namespace boost::geometry diff --git a/include/boost/geometry/util/readme.txt b/include/boost/geometry/util/readme.txt deleted file mode 100644 index 7a1bf88be..000000000 --- a/include/boost/geometry/util/readme.txt +++ /dev/null @@ -1,17 +0,0 @@ -// Boost.Geometry (aka GGL, Generic Geometry Library) - -// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands. -// Copyright (c) 2008-2011 Bruno Lalande, Paris, France. -// Copyright (c) 2009-2011 Mateusz Loskot, London, UK. - -// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library -// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. - -// Use, modification and distribution is subject to the Boost Software License, -// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -This folder contains several headerfiles not fitting in one of the other folders, -or meta-functions which would fit into boost as a separate trait or utility, -such as add_const_if_c - diff --git a/include/boost/geometry/util/type_traits.hpp b/include/boost/geometry/util/type_traits.hpp index 906c4cf1c..2fdd9f6a2 100644 --- a/include/boost/geometry/util/type_traits.hpp +++ b/include/boost/geometry/util/type_traits.hpp @@ -310,10 +310,53 @@ template using remove_cref_t = typename remove_cref::type; + +template +struct transcribe_const +{ + using type = std::conditional_t + < + std::is_const>::value, + std::add_const_t, + To + >; +}; + +template +using transcribe_const_t = typename transcribe_const::type; + + } // namespace detail #endif // DOXYGEN_NO_DETAIL +/*! + \brief Meta-function to define a const or non const type + \ingroup utility + \details If the boolean template parameter is true, the type parameter + will be defined as const, otherwise it will be defined as it was. + This meta-function is used to have one implementation for both + const and non const references + \note This traits class is completely independant from Boost.Geometry + and might be a separate addition to Boost + \note Used in a.o. for_each, interior_rings, exterior_ring + \par Example + \code + void foo(typename add_const_if_c::type& point) + \endcode +*/ +template +struct add_const_if_c +{ + typedef std::conditional_t + < + IsConst, + Type const, + Type + > type; +}; + + }} // namespace boost::geometry #endif // BOOST_GEOMETRY_STRATEGIES_DETAIL_HPP