| 114 | // FowardIterator or better, as we can use std::distance |
| 115 | template<class InputIt, class> |
| 116 | auto |
| 117 | string:: |
| 118 | replace( |
| 119 | const_iterator first, |
| 120 | const_iterator last, |
| 121 | InputIt first2, |
| 122 | InputIt last2) -> |
| 123 | string& |
| 124 | { |
| 125 | struct cleanup |
| 126 | { |
| 127 | detail::string_impl& s; |
| 128 | storage_ptr const& sp; |
| 129 | |
| 130 | ~cleanup() |
| 131 | { |
| 132 | s.destroy(sp); |
| 133 | } |
| 134 | }; |
| 135 | |
| 136 | // We use the default storage because |
| 137 | // the allocation is immediately freed. |
| 138 | storage_ptr dsp; |
| 139 | detail::string_impl tmp( |
| 140 | first2, last2, dsp, |
| 141 | iter_cat<InputIt>{}); |
| 142 | cleanup c{tmp, dsp}; |
| 143 | std::memcpy( |
| 144 | impl_.replace_unchecked( |
| 145 | first - begin(), |
| 146 | last - first, |
| 147 | tmp.size(), |
| 148 | sp_), |
| 149 | tmp.data(), |
| 150 | tmp.size()); |
| 151 | return *this; |
| 152 | } |
| 153 | |
| 154 | //---------------------------------------------------------- |
| 155 |