This reverts a large chunk of http://reviews.llvm.org/D15862 , and also fixes bugs in `insert`, `append`, and `assign`, which are now regression-tested. (Thanks to Tim Song for pointing out the bug in `append`!) Before this patch, we did a special dance in `append`, `assign`, and `insert` (but not `replace`). All of these require the strong exception guarantee, even when the user-provided InputIterator might have throwing operations. The naive way to accomplish this is to construct a temporary string and then append/assign/insert from the temporary; i.e., finish all the potentially throwing InputIterator operations *before* starting to modify the `*this` object. We need to do this in the following situations: - If reallocation is needed, but reallocation would invalidate the original iterators. (Append-from-self, for example.) - If reallocation is needed, but the original iterators' operations are throwing. We must provide the strong guarantee, and reallocation is an observable side effect, so if an iterator operation might throw, we must do all iterator operations prior to reallocating. - If the original iterators' operations are throwing and we're going to be making any "irreversible" modifications to the string's data. Appending to the end of the string doesn't count as irreversible, because we can just restore the null byte and we're all good. Inserting in the middle of the string counts as irreversible simply because we haven't written a codepath to reverse it. Most iterators have throwing (that is, non-noexcept) iterator operations. Pointers and some libc++-provided iterators can mark themselves as "trivial iterators" in order to get the non-naive behavior. The old SFINAE condition attempted to check the specific iterator operations ++, ==, etc., even for user-provided iterators; but it was so complicated that of course it was wrong; the new regression tests `basic.string/string.modifiers/string_{insert,append}/strong_guarantee.pass.cpp` both fail without this patch. Finally, ADL-proof the call to `__ptr_in_range` and add a regression test.
( Background: https://stackoverflow.com/questions/66459162/where-do-standard-library-or-compilers-leverage-noexcept-move-semantics-other-t/66498981#66498981 )
Oops, left over from debugging. Will let this sit for now, to let buildkite run the tests; but this new include will go away.