From eb0d01126a573a204c4382cbdde3a0bf8aa1924c Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Thu, 13 Jan 2022 16:59:46 +0300 Subject: [PATCH] Added support for int128 to counting_iterator. --- include/boost/iterator/counting_iterator.hpp | 29 ++++++++++++++++++-- test/counting_iterator_test.cpp | 8 ++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/include/boost/iterator/counting_iterator.hpp b/include/boost/iterator/counting_iterator.hpp index 45d4c83..65c11e9 100644 --- a/include/boost/iterator/counting_iterator.hpp +++ b/include/boost/iterator/counting_iterator.hpp @@ -67,11 +67,21 @@ namespace detail # if defined(BOOST_HAS_LONG_LONG) template <> - struct is_numeric< ::boost::long_long_type> + struct is_numeric : boost::true_type {}; template <> - struct is_numeric< ::boost::ulong_long_type> + struct is_numeric + : boost::true_type {}; +# endif + +# if defined(BOOST_HAS_INT128) + template <> + struct is_numeric + : boost::true_type {}; + + template <> + struct is_numeric : boost::true_type {}; # endif @@ -86,6 +96,21 @@ namespace detail typedef typename boost::detail::numeric_traits::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 { diff --git a/test/counting_iterator_test.cpp b/test/counting_iterator_test.cpp index ac382f0..09d4295 100644 --- a/test/counting_iterator_test.cpp +++ b/test/counting_iterator_test.cpp @@ -271,8 +271,12 @@ int main() test_integer(); test_integer(); #if defined(BOOST_HAS_LONG_LONG) - test_integer< ::boost::long_long_type>(); - test_integer< ::boost::ulong_long_type>(); + test_integer(); + test_integer(); +#endif +#if defined(BOOST_HAS_INT128) + test_integer(); + test_integer(); #endif // Test user-defined type.