| 77 | // FowardIterator or better, as we can use std::distance |
| 78 | template<class InputIt, class> |
| 79 | auto |
| 80 | string:: |
| 81 | insert( |
| 82 | size_type pos, |
| 83 | InputIt first, |
| 84 | InputIt last) -> |
| 85 | string& |
| 86 | { |
| 87 | struct cleanup |
| 88 | { |
| 89 | detail::string_impl& s; |
| 90 | storage_ptr const& sp; |
| 91 | |
| 92 | ~cleanup() |
| 93 | { |
| 94 | s.destroy(sp); |
| 95 | } |
| 96 | }; |
| 97 | |
| 98 | // We use the default storage because |
| 99 | // the allocation is immediately freed. |
| 100 | storage_ptr dsp; |
| 101 | detail::string_impl tmp( |
| 102 | first, last, dsp, |
| 103 | iter_cat<InputIt>{}); |
| 104 | cleanup c{tmp, dsp}; |
| 105 | std::memcpy( |
| 106 | impl_.insert_unchecked(pos, tmp.size(), sp_), |
| 107 | tmp.data(), |
| 108 | tmp.size()); |
| 109 | return *this; |
| 110 | } |
| 111 | |
| 112 | // KRYSTIAN TODO: this can be done without copies when |
| 113 | // reallocation is not needed, when the iterator is a |