Skip to content

Commit

Permalink
detail/iterator_traits: inherit from std::iterator_traits
Browse files Browse the repository at this point in the history
Using Boost.Move breaks range-v3, since the latter specializes
std::iterator_traits for its custom iterators.
  • Loading branch information
theodelrieu committed Sep 21, 2021
1 parent 6ab49a8 commit 38c0af2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
53 changes: 30 additions & 23 deletions include/boost/move/detail/iterator_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#endif

#include <cstddef>
#include <iterator>
#include <boost/move/detail/type_traits.hpp>

#include <boost/move/detail/std_ns_begin.hpp>
Expand All @@ -38,41 +39,47 @@ struct contiguous_iterator_tag;
BOOST_MOVE_STD_NS_END
#include <boost/move/detail/std_ns_end.hpp>

namespace boost{ namespace movelib{
namespace boost{ namespace move_detail{

template<class Iterator>
// SFINAE correct version of std::iterator_traits, see:
// https://cplusplus.github.io/LWG/issue2951
template <typename T, typename = void>
struct iterator_traits
{
typedef typename Iterator::difference_type difference_type;
typedef typename Iterator::value_type value_type;
typedef typename Iterator::pointer pointer;
typedef typename Iterator::reference reference;
typedef typename Iterator::iterator_category iterator_category;
typedef typename boost::move_detail::make_unsigned<difference_type>::type size_type;
};

template<class T>
struct iterator_traits<T*>
template <typename T>
struct iterator_traits<T, typename enable_if_c<!is_pointer<T>::value, void>::type>
: std::iterator_traits<T>
{
typedef std::ptrdiff_t difference_type;
typedef T value_type;
typedef T* pointer;
typedef T& reference;
typedef std::random_access_iterator_tag iterator_category;
typedef typename std::iterator_traits<T>::difference_type difference_type;
typedef typename std::iterator_traits<T>::pointer pointer;
typedef typename std::iterator_traits<T>::reference reference;
typedef typename std::iterator_traits<T>::iterator_category iterator_category;
typedef typename std::iterator_traits<T>::value_type value_type;

typedef typename boost::move_detail::make_unsigned<difference_type>::type size_type;
};

template<class T>
struct iterator_traits<const T*>
template <typename T>
struct iterator_traits<T*>
: std::iterator_traits<T*>
{
typedef std::ptrdiff_t difference_type;
typedef T value_type;
typedef const T* pointer;
typedef const T& reference;
typedef std::random_access_iterator_tag iterator_category;
typedef typename std::iterator_traits<T*>::difference_type difference_type;
typedef typename std::iterator_traits<T*>::pointer pointer;
typedef typename std::iterator_traits<T*>::reference reference;
typedef typename std::iterator_traits<T*>::iterator_category iterator_category;
typedef typename std::iterator_traits<T*>::value_type value_type;

typedef typename boost::move_detail::make_unsigned<difference_type>::type size_type;
};
} // namespace move_detail {

}} //namespace boost { namespace movelib{
namespace movelib{
template <typename T>
struct iterator_traits : move_detail::iterator_traits<T>
{
};
}} // namespace boost { namespace move_lib {

#endif //#ifndef BOOST_MOVE_DETAIL_ITERATOR_TRAITS_HPP
12 changes: 12 additions & 0 deletions include/boost/move/detail/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,18 @@ struct is_class
static const bool value = is_class_or_union<T>::value && ! is_union<T>::value;
};

//////////////////////////////////////
// is_object
//////////////////////////////////////

template <class T>
struct is_object
{
static const bool value = is_scalar<T>::value ||
is_array<T>::value ||
is_union<T>::value ||
is_class<T>::value;
};

//////////////////////////////////////
// is_arithmetic
Expand Down

0 comments on commit 38c0af2

Please sign in to comment.