forked from boostorg/static_string
Make erase follow preconditions
This commit is contained in:
@ -1863,8 +1863,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||||
iterator
|
iterator
|
||||||
erase(
|
erase(const_iterator pos)
|
||||||
const_iterator pos);
|
{
|
||||||
|
BOOST_STATIC_STRING_ASSERT(!empty());
|
||||||
|
return erase(pos, pos + 1);
|
||||||
|
}
|
||||||
|
|
||||||
/** Removes the characters in the range `(first, last)`
|
/** Removes the characters in the range `(first, last)`
|
||||||
|
|
||||||
@ -1892,7 +1895,7 @@ public:
|
|||||||
void
|
void
|
||||||
pop_back() noexcept
|
pop_back() noexcept
|
||||||
{
|
{
|
||||||
BOOST_STATIC_STRING_ASSERT(size() > 0);
|
BOOST_STATIC_STRING_ASSERT(!empty());
|
||||||
this->set_size(size() - 1);
|
this->set_size(size() - 1);
|
||||||
term();
|
term();
|
||||||
}
|
}
|
||||||
@ -5043,27 +5046,12 @@ erase(
|
|||||||
size_type count) ->
|
size_type count) ->
|
||||||
basic_static_string&
|
basic_static_string&
|
||||||
{
|
{
|
||||||
const auto curr_size = size();
|
|
||||||
const auto curr_data = data();
|
|
||||||
BOOST_STATIC_STRING_THROW_IF(
|
BOOST_STATIC_STRING_THROW_IF(
|
||||||
index > curr_size, std::out_of_range{"index > size()"});
|
index > size(), std::out_of_range{"index > size()"});
|
||||||
count = (std::min)(count, curr_size - index);
|
erase(data() + index, data() + index + (std::min)(count, size() - index));
|
||||||
traits_type::move(&curr_data[index], &curr_data[index + count], curr_size - (index + count) + 1);
|
|
||||||
this->set_size(curr_size - count);
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t N, typename CharT, typename Traits>
|
|
||||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
|
||||||
auto
|
|
||||||
basic_static_string<N, CharT, Traits>::
|
|
||||||
erase(const_iterator pos) ->
|
|
||||||
iterator
|
|
||||||
{
|
|
||||||
erase(pos - begin(), 1);
|
|
||||||
return begin() + (pos - begin());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<std::size_t N, typename CharT, typename Traits>
|
template<std::size_t N, typename CharT, typename Traits>
|
||||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||||
auto
|
auto
|
||||||
@ -5073,9 +5061,11 @@ erase(
|
|||||||
const_iterator last) ->
|
const_iterator last) ->
|
||||||
iterator
|
iterator
|
||||||
{
|
{
|
||||||
erase(first - begin(),
|
const auto curr_data = data();
|
||||||
detail::distance(first, last));
|
const std::size_t index = first - curr_data;
|
||||||
return begin() + (first - begin());
|
traits_type::move(&curr_data[index], last, (end() - last) + 1);
|
||||||
|
this->set_size(size() - std::size_t(last - first));
|
||||||
|
return curr_data + index;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t N, typename CharT, typename Traits>
|
template<std::size_t N, typename CharT, typename Traits>
|
||||||
|
@ -134,7 +134,7 @@ testConstantEvaluation()
|
|||||||
a.insert(a.begin(), {'a'});
|
a.insert(a.begin(), {'a'});
|
||||||
|
|
||||||
// erase
|
// erase
|
||||||
a.erase();
|
a.erase(0, 1);
|
||||||
a.erase(a.begin());
|
a.erase(a.begin());
|
||||||
a.erase(a.begin(), a.end());
|
a.erase(a.begin(), a.end());
|
||||||
|
|
||||||
@ -324,7 +324,7 @@ testConstantEvaluation()
|
|||||||
a.insert(a.begin(), {'a'});
|
a.insert(a.begin(), {'a'});
|
||||||
|
|
||||||
// erase
|
// erase
|
||||||
a.erase();
|
a.erase(0, 1);
|
||||||
a.erase(a.begin());
|
a.erase(a.begin());
|
||||||
a.erase(a.begin(), a.end());
|
a.erase(a.begin(), a.end());
|
||||||
|
|
||||||
@ -500,7 +500,7 @@ testConstantEvaluation()
|
|||||||
a.insert(a.begin(), {'a'});
|
a.insert(a.begin(), {'a'});
|
||||||
|
|
||||||
// erase
|
// erase
|
||||||
a.erase();
|
a.erase(0, 1);
|
||||||
a.erase(a.begin());
|
a.erase(a.begin());
|
||||||
a.erase(a.begin(), a.end());
|
a.erase(a.begin(), a.end());
|
||||||
|
|
||||||
|
@ -1608,11 +1608,6 @@ testErase()
|
|||||||
BOOST_TEST(s.erase(s.begin() + 1) == s.begin() + 1);
|
BOOST_TEST(s.erase(s.begin() + 1) == s.begin() + 1);
|
||||||
BOOST_TEST(s == "ac");
|
BOOST_TEST(s == "ac");
|
||||||
}
|
}
|
||||||
{
|
|
||||||
static_string<3> s{"abc"};
|
|
||||||
BOOST_TEST(s.erase(s.begin() + 3) == s.end());
|
|
||||||
BOOST_TEST(s == "abc");
|
|
||||||
}
|
|
||||||
|
|
||||||
// erase(const_iterator first, const_iterator last)
|
// erase(const_iterator first, const_iterator last)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user