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 a14c485 commit e73b92a
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions include/boost/move/detail/iterator_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ 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{

// SFINAE correct version of std::iterator_traits, see:
// https://cplusplus.github.io/LWG/issue2951
Expand All @@ -49,23 +48,37 @@ struct iterator_traits
};

template <typename T>
struct iterator_traits<T, move_detail::enable_if<!move_detail::is_pointer<T>::value>>
struct iterator_traits<T, typename enable_if_c<!std::is_pointer<T>::value, void>::type>
: std::iterator_traits<T>
{
using typename std::iterator_traits<T*>::difference_type;
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 <typename T>
struct iterator_traits<T*, move_detail::enable_if<move_detail::is_object<T>::value>>
struct iterator_traits<T*, typename enable_if_c<std::is_object<T>::value, void>::type>
: std::iterator_traits<T*>
{
using typename std::iterator_traits<T*>::difference_type;
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 e73b92a

Please sign in to comment.