Changed iterator_category nested type detection to work with MSVC and different versions of gcc.

This commit is contained in:
Andrey Semashev 2017-07-12 20:14:48 +03:00
parent ec50f22b8b
commit 5bc9e47688

View File

@ -17,6 +17,7 @@
#include <iterator> #include <iterator>
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/type_traits/has_plus.hpp> #include <boost/type_traits/has_plus.hpp>
#include <boost/type_traits/has_plus_assign.hpp> #include <boost/type_traits/has_plus_assign.hpp>
#include <boost/type_traits/has_minus.hpp> #include <boost/type_traits/has_minus.hpp>
@ -42,24 +43,20 @@ namespace next_prior_detail {
// Still, this is a good heuristic in practice, and we can't do anything better anyway. // Still, this is a good heuristic in practice, and we can't do anything better anyway.
// Since C++17 we can test for iterator_traits<T>::iterator_category presence instead as it is // Since C++17 we can test for iterator_traits<T>::iterator_category presence instead as it is
// required to be only present for iterators. // required to be only present for iterators.
template< typename T > template< typename T, typename Void = void >
struct is_iterator struct is_iterator
{ {
private: static BOOST_CONSTEXPR_OR_CONST bool value = false;
typedef char yes_type;
typedef char (&no_type)[2];
template< typename U >
static yes_type check_iterator_category(typename U::iterator_category*);
template< typename U >
static no_type check_iterator_category(...);
public:
static BOOST_CONSTEXPR_OR_CONST bool value = sizeof(is_iterator< T >::BOOST_NESTED_TEMPLATE check_iterator_category< T >(0)) == sizeof(yes_type);
}; };
template< typename T > template< typename T >
struct is_iterator< T* > struct is_iterator< T, typename enable_if_has_type< typename T::iterator_category >::type >
{
static BOOST_CONSTEXPR_OR_CONST bool value = true;
};
template< typename T >
struct is_iterator< T*, void >
{ {
static BOOST_CONSTEXPR_OR_CONST bool value = true; static BOOST_CONSTEXPR_OR_CONST bool value = true;
}; };