<div dir="ltr"><div>Recently, "TC" reported a bug against libc++'s string implementation.</div><div>    <a href="https://llvm.org/bugs/show_bug.cgi?id=25973">https://llvm.org/bugs/show_bug.cgi?id=25973</a></div><div><br></div><div>It seems that libc++'s string was not behaving correctly on calls to assign/replace/insert/append when exceptions were thrown - the string is required by the standard to remain unchanged in those cases (in some cases, libc++ would leave the string in a damaged, unusable state)</div><div><br></div><div>I have fixed this in: <a href="http://reviews.llvm.org/D15862">http://reviews.llvm.org/D15862</a> (not yet landed), but doing so requires some extra work. In particular, it requires constructing a temporary string and then moving the contents into the destination.  (possible allocation, definitely copying).</div><div><br></div><div>For many iterators, these precautions are unnecessary, because they won't throw exceptions. Libc++ attempts to recognize them and does the efficient thing in these cases.  Pointers, for example. libc++'s vector/string iterators (when not using fancy pointers) are other examples.</div><div><br></div><div>There's also a test for the general case. If the iterator operations that string uses are marked as `noexcept`, then you'll get the (more) efficient code path. What are those operations?</div><div>    * dereference (i.e, *iter)</div><div>    * prefix increment (i.e, ++iter)</div><div>    * comparison ( iter1 == iter2 )</div><div>    * assignment ( iter1 = iter2 )</div><div><br></div><div>So, if you have custom iterators, and take a look at those operations and see if you can make them noexcept. </div><div><br></div><div>-- Marshall</div><div><br></div></div>