<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On Apr 19, 2014, at 7:52 AM, Gonzalo BG <<a href="mailto:gonzalobg88@gmail.com">gonzalobg88@gmail.com</a>> wrote:<br><div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Thanks for adding the section.<div><br></div><div>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):</div></div></blockquote><div><br></div>Thanks for the example; I’ll try it out on Monday.</div><div><br></div><div>However, I think you’re out of luck, anyway, because of [iterator.requirements.general]/p1; the last sentence:</div><div><div><br></div><div> For every iterator type X for which equality is defined, there is a corresponding signed integer type called the difference type of the iterator.</div><div><br></div><div>And [basic.fundamental]/p2, which says:</div><div><br></div><div> There are five standard signed integer types : “signed char”, “short int”, “int”, “long int”, and “long long int”.</div><div>followed by:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>There may also be implementation-defined extended signed integer types. The standard and extended signed integer types are collectively called signed integer types. </div><div><br></div><div>To me this says that you can’t have an standard-conforming iterator with a difference_type that isn’t one of those types.</div><div><br></div><div>[ And a brief search of the standards committee mailing list found a discussion on exactly this point back in August of 2012,</div><div>and the consensus was that the standard did not allow iterators with such difference types. ]</div><div><br></div><div>Just FYI: The difference_type of the standard containers and allocators is defined the same way.</div><div><br></div><div>— Marshall</div><div><br></div><div><br></div></div><div><blockquote type="cite"><div dir="ltr">
<div><br></div><div><div>#include <algorithm></div><div>#include <boost/iterator/counting_iterator.hpp></div><div>// From <a href="https://github.com/gnzlbg/arithmetic_type">https://github.com/gnzlbg/arithmetic_type</a> :</div>
<div>#include <arithmetic_type/arithmetic_type.hpp> </div><div><br></div><div>int main() {</div><div> /// Opaque Integer without implicit conversions:</div><div> struct tag {};</div><div> using Int = arithmetic::Arithmetic<int, tag>;</div>
<div><br></div><div> /// Works as expected</div><div> boost::counting_iterator<Int, boost::random_access_traversal_tag, Int> a(Int{10});</div><div> std::advance(a, Int{5});</div><div><br></div><div> /// Fails: libcxx/iterator:458:13: error: invalid operands to</div>
<div> /// binary expression ('typename</div><div> /// iterator_traits<counting_iterator<Arithmetic<int, tag>,</div><div> /// bidirectional_traversal_tag, Arithmetic<int, tag> > >::difference_type'</div>
<div> /// (aka 'arithmetic::Arithmetic<int, tag>') and 'int')</div><div> /// if (__n >= 0)</div><div> /// ~~~ ^ ~</div><div> boost::counting_iterator<Int, boost::bidirectional_traversal_tag, Int> b(Int{10});</div>
<div> std::advance(b, Int{5});</div><div><br></div><div> /// Fails: libcxx/iterator:449:16: error: invalid operands to binary</div><div> /// expression ('typename iterator_traits<counting_iterator<Arithmetic<int, tag>,</div>
<div> /// forward_traversal_tag, Arithmetic<int, tag> > >::difference_type' (aka</div><div> /// 'arithmetic::Arithmetic<int, tag>') and 'int')</div><div> /// for (; __n > 0; --__n)</div>
<div> /// ~~~ ^ ~</div><div> boost::counting_iterator<Int, boost::forward_traversal_tag, Int> c(Int{10});</div><div> std::advance(c, Int{5});</div><div>}</div></div><div><br></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Thu, Apr 3, 2014 at 5:20 AM, Marshall Clow <span dir="ltr"><<a href="mailto:mclow.lists@gmail.com" target="_blank">mclow.lists@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="">On Mar 22, 2014, at 8:45 AM, Marshall Clow <<a href="mailto:mclow.lists@gmail.com">mclow.lists@gmail.com</a>> wrote:<br>
<br>
> P.P.S. I’ll take a look at adding info to the libc++ web page.<br>
<br>
</div>I’ve added a section to <a href="http://libcxx.llvm.org/" target="_blank">http://libcxx.llvm.org</a> about reporting bugs and contributing patches<br>
<span class="HOEnZb"><font color="#888888"><br>
— Marshall<br>
<br>
<br>
</font></span></blockquote></div><br></div>
</blockquote></div><br></body></html>