From 0c6b09ef6aa318b794dca2beafeeee3a6e77f239 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sun, 27 Aug 2017 17:31:34 +0300 Subject: [PATCH] Workaround MSVC 14.1 problem with template specialization partial ordering that caused compilation failure when next/prior is used with pointers. Added a test. --- include/boost/next_prior.hpp | 12 +++++++++--- test/next_prior_test.cpp | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/boost/next_prior.hpp b/include/boost/next_prior.hpp index 178cf67..5de705f 100644 --- a/include/boost/next_prior.hpp +++ b/include/boost/next_prior.hpp @@ -46,13 +46,13 @@ namespace next_prior_detail { // Since C++17 we can test for iterator_traits::iterator_category presence instead as it is // required to be only present for iterators. template< typename T, typename Void = void > -struct is_iterator +struct is_iterator_class { static BOOST_CONSTEXPR_OR_CONST bool value = false; }; template< typename T > -struct is_iterator< +struct is_iterator_class< T, typename enable_if_has_type< #if !defined(BOOST_NO_CXX17_ITERATOR_TRAITS) @@ -67,7 +67,13 @@ struct is_iterator< }; template< typename T > -struct is_iterator< T*, void > +struct is_iterator : + public is_iterator_class< T > +{ +}; + +template< typename T > +struct is_iterator< T* > { static BOOST_CONSTEXPR_OR_CONST bool value = true; }; diff --git a/test/next_prior_test.cpp b/test/next_prior_test.cpp index 734a212..65e74b1 100644 --- a/test/next_prior_test.cpp +++ b/test/next_prior_test.cpp @@ -92,6 +92,15 @@ int main(int, char*[]) BOOST_TEST(minus_n_unsigned_test(x.rbegin(), x.rend(), x.size())); BOOST_TEST(minus_n_unsigned_test(x.rbegin(), x.rend(), y.size())); + // Test with pointers + int arr[8] = {}; + int* p = arr; + BOOST_TEST(plus_one_test(x.begin(), x.end(), p)); + BOOST_TEST(plus_n_test(x.begin(), x.end(), p)); + BOOST_TEST(minus_one_test(x.begin(), x.end(), p + sizeof(arr))); + BOOST_TEST(minus_n_test(x.begin(), x.end(), p + sizeof(arr))); + BOOST_TEST(minus_n_unsigned_test(p, p + sizeof(arr), sizeof(arr))); + // Tests with integers BOOST_TEST(boost::next(5) == 6); BOOST_TEST(boost::next(5, 7) == 12);