From c2c50054f9b41bbbb0285283afaaa14ee7a2106b Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Fri, 18 Oct 2019 20:50:42 -0400 Subject: [PATCH] replace impl added --- include/boost/fixed_string/fixed_string.hpp | 29 +++++++++++-- .../boost/fixed_string/impl/fixed_string.hpp | 41 +++++++++++++++++++ 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/include/boost/fixed_string/fixed_string.hpp b/include/boost/fixed_string/fixed_string.hpp index a1671a6..f412bd1 100644 --- a/include/boost/fixed_string/fixed_string.hpp +++ b/include/boost/fixed_string/fixed_string.hpp @@ -1303,7 +1303,14 @@ public: } template +#if GENERATING_DOCUMENTATION fixed_string& +#else + typename std::enable_if< + std::is_convertible::value && + ! std::is_convertible::value, + fixed_string&>::type +#endif replace( size_type pos1, size_type n1, @@ -1314,7 +1321,14 @@ public: } template +#if GENERATING_DOCUMENTATION fixed_string& +#else + typename std::enable_if< + std::is_convertible::value && + ! std::is_convertible::value, + fixed_string&>::type +#endif replace( size_type pos1, size_type n1, @@ -1340,7 +1354,7 @@ public: size_type n1, const CharT* s) { - return replace(pos, n, s, Traits::length(s)); + return replace(pos, n1, s, Traits::length(s)); } // impl @@ -1361,7 +1375,14 @@ public: } template +#if GENERATING_DOCUMENTATION fixed_string& +#else + typename std::enable_if< + std::is_convertible::value && + ! std::is_convertible::value, + fixed_string&>::type +#endif replace( const_iterator i1, const_iterator i2, @@ -1413,9 +1434,9 @@ public: fixed_string& replace( - const_iterator, - const_iterator, - std::initializer_list) + const_iterator i1, + const_iterator i2, + std::initializer_list il) { return replace(i1, i2, il.begin(), il.size()); } diff --git a/include/boost/fixed_string/impl/fixed_string.hpp b/include/boost/fixed_string/impl/fixed_string.hpp index 543c583..056d6a0 100644 --- a/include/boost/fixed_string/impl/fixed_string.hpp +++ b/include/boost/fixed_string/impl/fixed_string.hpp @@ -569,6 +569,47 @@ swap(fixed_string& s) Traits::copy(&s_[0], &tmp.s_[0], n_ + 1); } +auto +fixed_string:: +replace( + size_type pos, + size_type n1, + const CharT* s, + size_type n2) -> fixed_string& +{ + if (pos > size()) + BOOST_THROW_EXCEPTION(std::out_of_range{ + "pos > size()"}); + if ((size() - n1 + n2) > max_size()) + BOOST_THROW_EXCEPTION(std::length_error{ + "replaced string exceeds max_size()"}); + Traits::move(&s_[pos + n2], &s_[pos + n1], size() - pos - n1 + 1); + Traits::copy(&s_[pos], s, n2); + n_ += (n2 - n1); + return *this; +} + +template +auto +fixed_string:: +replace( + size_type pos, + size_type n1, + size_type n2, + CharT c) -> fixed_string & +{ + if (pos > size()) + BOOST_THROW_EXCEPTION(std::out_of_range{ + "pos > size()"}); + if ((size() - n1 + n2) > max_size()) + BOOST_THROW_EXCEPTION(std::length_error{ + "replaced string exceeds max_size()"}); + Traits::move(&s_[pos + n2], &s_[pos + n1], size() - pos - n1 + 1); + Traits::assign(&s_[pos], n2, c); + n_ += (n2 - n1); + return *this; +} + template auto