Thanks for adding the section.

I’ve tried hard to come up with a MWE that is simpler than this, but I’ve failed. This is the simplest thing I’ve been able to come up with. As you can see, the code works fine for random access iterators, but fails for bidirectional and forward iterators (see the errors below in the comments):

#include

#include <boost/iterator/counting_iterator.hpp>

// From https://github.com/gnzlbg/arithmetic_type :

#include <arithmetic_type/arithmetic_type.hpp>

int main() {

/// Opaque Integer without implicit conversions:

struct tag {};

using Int = arithmetic::Arithmetic<int, tag>;

/// Works as expected

boost::counting_iterator<Int, boost::random_access_traversal_tag, Int> a(Int{10});

std::advance(a, Int{5});

/// Fails: libcxx/iterator:458:13: error: invalid operands to

/// binary expression (‘typename

/// iterator_traits<counting_iterator<Arithmetic<int, tag>,

/// bidirectional_traversal_tag, Arithmetic<int, tag> > >::difference_type’

/// (aka ‘arithmetic::Arithmetic<int, tag>’) and ‘int’)

/// if (__n >= 0)

/// ~~~ ^ ~

boost::counting_iterator<Int, boost::bidirectional_traversal_tag, Int> b(Int{10});

std::advance(b, Int{5});

/// Fails: libcxx/iterator:449:16: error: invalid operands to binary

/// expression (‘typename iterator_traits<counting_iterator<Arithmetic<int, tag>,

/// forward_traversal_tag, Arithmetic<int, tag> > >::difference_type’ (aka

/// ‘arithmetic::Arithmetic<int, tag>’) and ‘int’)

/// for (; __n > 0; --__n)

/// ~~~ ^ ~

boost::counting_iterator<Int, boost::forward_traversal_tag, Int> c(Int{10});

std::advance(c, Int{5});

}