diff --git a/include/boost/fixed_string/fixed_string.hpp b/include/boost/fixed_string/fixed_string.hpp index 0163181..0d8a3ce 100644 --- a/include/boost/fixed_string/fixed_string.hpp +++ b/include/boost/fixed_string/fixed_string.hpp @@ -1340,7 +1340,6 @@ public: return replace(pos1, n1, sv.substr(pos2, n2)); } - // impl fixed_string& replace( size_type pos, @@ -1357,7 +1356,6 @@ public: return replace(pos, n1, s, Traits::length(s)); } - // impl fixed_string& replace( size_type pos, @@ -1422,7 +1420,13 @@ public: } template +#if GENERATING_DOCUMENTATION fixed_string& +#else + typename std::enable_if< + detail::is_input_iterator::value, + fixed_string&>::type +#endif replace( const_iterator i1, const_iterator i2, @@ -1568,7 +1572,7 @@ public: { return string_view_type( *this).rfind( - s, pos); + s, pos, n); } /** Finds the last substring equal to the character diff --git a/include/boost/fixed_string/impl/fixed_string.hpp b/include/boost/fixed_string/impl/fixed_string.hpp index cf8f982..9d50195 100644 --- a/include/boost/fixed_string/impl/fixed_string.hpp +++ b/include/boost/fixed_string/impl/fixed_string.hpp @@ -317,10 +317,28 @@ insert( if(size() + count > max_size()) BOOST_THROW_EXCEPTION(std::length_error{ "size() + count > max_size()"}); - Traits::move( - &s_[index + count], &s_[index], size() - index); + const bool inside = s <= &s_[size()] && s >= &s_[0]; + if (!inside || (inside && (&s[count - 1] < &s_[index]))) + { + Traits::move(&s_[index + count], &s_[index], size() - index); + Traits::copy(&s_[index], s, count); + } + else + { + const size_type offset = s - &s_[0]; + Traits::move(&s_[index + count], &s_[index], size() - index); + if (offset < index) + { + const size_type diff = index - offset; + Traits::copy(&s_[index], &s_[offset], diff); + Traits::copy(&s_[index + diff], &s_[index + count], count - diff); + } + else + { + Traits::copy(&s_[index], &s_[index + count + offset], count); + } + } n_ += count; - Traits::copy(&s_[index], s, count); term(); return *this; } @@ -363,12 +381,13 @@ insert( BOOST_THROW_EXCEPTION(std::length_error{ "size() + count > max_size()"}); std::size_t const index = pos - begin(); - Traits::move( - &s_[index + count], &s_[index], size() - index); - n_ += count; + if (&*first <= &s_[size()] && &*first >= &s_[0]) + return insert(index, &*first, count).begin() + index; + Traits::move(&s_[index + count], &s_[index], size() - index); for(auto it = begin() + index; first != last; ++it, ++first) Traits::assign(*it, *first); + n_ += count; term(); return begin() + index; }