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 20, 2021
1 parent 6ab49a8 commit fe7fb49
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 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 @@ -33,46 +34,51 @@ struct forward_iterator_tag;
struct bidirectional_iterator_tag;
struct random_access_iterator_tag;
struct output_iterator_tag;
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<!std::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*, typename enable_if_c<std::is_object<T>::value, void>::type>
: 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

0 comments on commit fe7fb49

Please sign in to comment.