From d6a68dc6eb0057173afc6a77eb15792a4afe4c6a Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Wed, 29 Jan 2025 03:38:46 +0300 Subject: [PATCH] Removed workarounds for older compilers from counting_iterator.hpp. --- include/boost/iterator/counting_iterator.hpp | 314 ++++++++----------- 1 file changed, 137 insertions(+), 177 deletions(-) diff --git a/include/boost/iterator/counting_iterator.hpp b/include/boost/iterator/counting_iterator.hpp index 55cc517..1bac414 100644 --- a/include/boost/iterator/counting_iterator.hpp +++ b/include/boost/iterator/counting_iterator.hpp @@ -5,209 +5,171 @@ #ifndef COUNTING_ITERATOR_DWA200348_HPP #define COUNTING_ITERATOR_DWA200348_HPP +#include #include #include -#include -#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS -#include -#endif #include #include #include +#include #include namespace boost { namespace iterators { -template < - class Incrementable - , class CategoryOrTraversal - , class Difference +template< + class Incrementable, + class CategoryOrTraversal, + class Difference > class counting_iterator; -namespace detail +namespace detail { + +// Try to detect numeric types at compile time in ways compatible +// with the limitations of the compiler and library. +template +struct is_numeric : + public std::integral_constant::is_specialized> +{}; + +template <> +struct is_numeric : + public std::true_type +{}; + +template <> +struct is_numeric : + public std::true_type +{}; + +#if defined(BOOST_HAS_INT128) +template <> +struct is_numeric : + public std::true_type +{}; + +template <> +struct is_numeric : + public std::true_type +{}; +#endif + +// Some compilers fail to have a numeric_limits specialization +template <> +struct is_numeric : + public std::true_type +{}; + +template +struct numeric_difference { - // Try to detect numeric types at compile time in ways compatible - // with the limitations of the compiler and library. - template - struct is_numeric_impl - { -#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS - - BOOST_STATIC_CONSTANT(bool, value = std::numeric_limits::is_specialized); - -#else - -#if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x551)) - BOOST_STATIC_CONSTANT( - bool, value = ( - std::is_convertible::value - && std::is_convertible::value - )); -#else - BOOST_STATIC_CONSTANT(bool, value = std::is_arithmetic::value); -#endif - -#endif - }; - - template - struct is_numeric - : std::integral_constant::value> - {}; - - template <> - struct is_numeric - : std::true_type {}; - - template <> - struct is_numeric - : std::true_type {}; + using type = typename boost::detail::numeric_traits::difference_type; +}; #if defined(BOOST_HAS_INT128) - template <> - struct is_numeric - : std::true_type {}; +// std::numeric_limits, which is used by numeric_traits, is not specialized for __int128 in some standard libraries +template <> +struct numeric_difference +{ + using type = boost::int128_type; +}; - template <> - struct is_numeric - : std::true_type {}; +template <> +struct numeric_difference +{ + using type = boost::int128_type; +}; #endif - // Some compilers fail to have a numeric_limits specialization - template <> - struct is_numeric - : std::true_type {}; +template +struct counting_iterator_base +{ + using traversal = typename detail::ia_dflt_help< + CategoryOrTraversal, + typename std::conditional< + is_numeric::value, + iterators::detail::type_identity, + iterator_traversal + >::type + >::type; - template - struct numeric_difference - { - typedef typename boost::detail::numeric_traits::difference_type type; - }; + using difference = typename detail::ia_dflt_help< + Difference, + typename std::conditional< + is_numeric::value, + numeric_difference, + iterator_difference + >::type + >::type; -#if defined(BOOST_HAS_INT128) - // std::numeric_limits, which is used by numeric_traits, is not specialized for __int128 in some standard libraries - template <> - struct numeric_difference - { - typedef boost::int128_type type; - }; - - template <> - struct numeric_difference - { - typedef boost::int128_type type; - }; -#endif - - template - struct counting_iterator_base - { - typedef typename detail::ia_dflt_help< - CategoryOrTraversal - , typename std::conditional< - is_numeric::value - , iterators::detail::type_identity - , iterator_traversal - >::type - >::type traversal; - - typedef typename detail::ia_dflt_help< - Difference - , typename std::conditional< - is_numeric::value - , numeric_difference - , iterator_difference - >::type - >::type difference; - - typedef iterator_adaptor< - counting_iterator // self - , Incrementable // Base - , Incrementable // Value + using type = iterator_adaptor< + counting_iterator, // self + Incrementable, // Base #ifndef BOOST_ITERATOR_REF_CONSTNESS_KILLS_WRITABILITY - const // MSVC won't strip this. Instead we enable Thomas' - // criterion (see boost/iterator/detail/facade_iterator_category.hpp) + const // MSVC won't strip this. Instead we enable Thomas' + // criterion (see boost/iterator/detail/facade_iterator_category.hpp) #endif - , traversal - , Incrementable const& // reference - , difference - > type; - }; + Incrementable, // Value + traversal, + Incrementable const&, // reference + difference + >; +}; - // Template class distance_policy_select -- choose a policy for computing the - // distance between counting_iterators at compile-time based on whether or not - // the iterator wraps an integer or an iterator, using "poor man's partial - // specialization". - - template struct distance_policy_select; - - // A policy for wrapped iterators - template - struct iterator_distance - { - static Difference distance(Incrementable1 x, Incrementable2 y) - { - return y - x; - } - }; - - // A policy for wrapped numbers - template - struct number_distance - { - static Difference distance(Incrementable1 x, Incrementable2 y) - { - return boost::detail::numeric_distance(x, y); - } - }; -} - -template < - class Incrementable - , class CategoryOrTraversal = use_default - , class Difference = use_default -> -class counting_iterator - : public detail::counting_iterator_base< - Incrementable, CategoryOrTraversal, Difference - >::type +// A distance calculation policy for wrapped iterators +template +struct iterator_distance { - typedef typename detail::counting_iterator_base< + static Difference distance(Incrementable1 x, Incrementable2 y) + { + return y - x; + } +}; + +// A distance calculation policy for wrapped numbers +template +struct number_distance +{ + static Difference distance(Incrementable1 x, Incrementable2 y) + { + return boost::detail::numeric_distance(x, y); + } +}; + +} // namespace detail + +template< + class Incrementable, + class CategoryOrTraversal = use_default, + class Difference = use_default +> +class counting_iterator : + public detail::counting_iterator_base::type +{ + using super_t = typename detail::counting_iterator_base< Incrementable, CategoryOrTraversal, Difference - >::type super_t; + >::type; friend class iterator_core_access; - public: - typedef typename super_t::difference_type difference_type; +public: + using reference = typename super_t::reference; + using difference_type = typename super_t::difference_type; - BOOST_DEFAULTED_FUNCTION(counting_iterator(), {}) + counting_iterator() = default; - BOOST_DEFAULTED_FUNCTION(counting_iterator(counting_iterator const& rhs), : super_t(rhs.base()) {}) + counting_iterator(counting_iterator const&) = default; + counting_iterator& operator=(counting_iterator const&) = default; - counting_iterator(Incrementable x) - : super_t(x) + counting_iterator(Incrementable x) : + super_t(x) { } -#if 0 - template - counting_iterator( - counting_iterator const& t - , typename enable_if_convertible::type* = 0 - ) - : super_t(t.base()) - {} -#endif - - BOOST_DEFAULTED_FUNCTION(counting_iterator& operator=(counting_iterator const& rhs), { *static_cast< super_t* >(this) = static_cast< super_t const& >(rhs); return *this; }) - - private: - - typename super_t::reference dereference() const +private: + reference dereference() const { return this->base_reference(); } @@ -216,23 +178,21 @@ class counting_iterator difference_type distance_to(counting_iterator const& y) const { - typedef typename std::conditional< - detail::is_numeric::value - , detail::number_distance - , detail::iterator_distance - >::type d; + using distance_traits = typename std::conditional< + detail::is_numeric::value, + detail::number_distance, + detail::iterator_distance + >::type; - return d::distance(this->base(), y.base()); + return distance_traits::distance(this->base(), y.base()); } }; // Manufacture a counting iterator for an arbitrary incrementable type template -inline counting_iterator -make_counting_iterator(Incrementable x) +inline counting_iterator make_counting_iterator(Incrementable x) { - typedef counting_iterator result_t; - return result_t(x); + return counting_iterator(x); } } // namespace iterators