<div dir="ltr">My iterator is using as difference_type this user-defined integer (<a href="https://github.com/gnzlbg/arithmetic_type">https://github.com/gnzlbg/arithmetic_type</a>) which can't be compared with int and is only explicitly convertible to other types. <div>

<br></div><div>I just reproduced the exact error I was getting. It fails due to the lack of operator< for my difference_type and int. </div><div><br></div><div>> <span style="font-family:arial,sans-serif;font-size:12.800000190734863px">I don’t see any provision here for an iterator having a difference_type that is a user-defined type.</span></div>

<div><br></div><div>I don't think the standard allows user-defined integer types with extraneous conversion rules as difference_type either. </div><div><br></div><div>><span style="font-family:arial,sans-serif;font-size:12.800000190734863px">I’d really, really like to see a failing test case that I can include in the libc++ test suite.</span></div>

<div style="font-family:arial,sans-serif;font-size:12.800000190734863px">Otherwise, someone might break it again in the future.</div><div><br></div><div>Since all integer types can be compared with int, one would need a custom integer type to construct a test for this. I can provide a random access counting range this week, whose counting iterators have this custom integer as difference_type if there is interest for it.</div>

<div><br></div><div>The arguments behind this patch are weak. There are probably multiple occurrences of similar constructs within the standard library. Using a custom integer without implicit conversions would require that the types match exactly (e.g. difference_type{0}), and that all type conversions are made explicit (e.g. via a static_cast). I don't know if this is worth pursuing due to its low ROI. If this would be worth pursuing, adding a clang warning for mismatching integer types would probably be a better way of ensuring this than run-time tests.</div>

</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Mar 22, 2014 at 4:58 PM, 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 style="word-wrap:break-word"><br><div><div class=""><div>On Mar 20, 2014, at 1:22 PM, Gonzalo BG <<a href="mailto:gonzalobg88@gmail.com" target="_blank">gonzalobg88@gmail.com</a>> wrote:</div>

<br></div><div><div class="h5"><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Mar 20, 2014 at 9:09 PM, Joerg Sonnenberger <span dir="ltr"><<a href="mailto:joerg@britannica.bec.de" target="_blank">joerg@britannica.bec.de</a>></span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Do you have a test case that failed before?</blockquote></div><br>I have an iterator with a difference_type that is only explicitly convertible from int (not implicitly) and thus fails. Its implementation depends on Boost.Iterator (and everything that Boost.Iterator depends on) so I don't think it would be suitable for a test-case.</div>

</div></blockquote><br></div></div></div><div>I’m also wondering about this.</div><div><br></div><div>The standard says that an iterator’s difference_type must be a ‘signed integer type” section 24.2.1 [iterator.requirements.general]</div>

<div><br></div><div>These types are defined in section 3.9.1 [basic.fundamental], and seems to me to imply that it has to be either one of  “signed char”, “short int”, “int”, “long int”, and “long long int”, or an “extended signed integer type” provided by the implementation (which means the compiler and/or standard library). I don’t see any provision here for an iterator having a difference_type that is a user-defined type.</div>

<div><br></div><div>Off to read the Boost.Iterator documentation….</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>— Marshall</div><div><br></div><br></font></span></div></blockquote></div><br></div>