Workaround MSVC 14.1 problem with template specialization partial ordering that caused compilation failure when next/prior is used with pointers. Added a test.

This commit is contained in:
Andrey Semashev
2017-08-27 17:31:34 +03:00
parent 3275ee3c82
commit 0c6b09ef6a
2 changed files with 18 additions and 3 deletions

View File

@ -46,13 +46,13 @@ namespace next_prior_detail {
// Since C++17 we can test for iterator_traits<T>::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;
};

View File

@ -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);