Merge pull request #98 from boostorg/feature/string_view_remove_prefix_suffix_precondition

string_view: Change string_view::remove_prefix/suffix preconditions to use asserts
This commit is contained in:
Andrey Semashev 2022-07-06 03:14:43 +03:00 committed by GitHub
commit 028a90b29d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,6 +23,7 @@
#include <boost/io/ostream_put.hpp> #include <boost/io/ostream_put.hpp>
#include <boost/utility/string_view_fwd.hpp> #include <boost/utility/string_view_fwd.hpp>
#include <boost/throw_exception.hpp> #include <boost/throw_exception.hpp>
#include <boost/assert.hpp>
#include <cstddef> #include <cstddef>
#include <stdexcept> #include <stdexcept>
@ -140,6 +141,8 @@ namespace boost {
void clear() BOOST_NOEXCEPT { len_ = 0; } // Boost extension void clear() BOOST_NOEXCEPT { len_ = 0; } // Boost extension
BOOST_CXX14_CONSTEXPR void remove_prefix(size_type n) { BOOST_CXX14_CONSTEXPR void remove_prefix(size_type n) {
BOOST_ASSERT(n <= size());
// This check is deprecated and is left for backward compatibility. It will be removed in the future.
if ( n > len_ ) if ( n > len_ )
n = len_; n = len_;
ptr_ += n; ptr_ += n;
@ -147,6 +150,8 @@ namespace boost {
} }
BOOST_CXX14_CONSTEXPR void remove_suffix(size_type n) { BOOST_CXX14_CONSTEXPR void remove_suffix(size_type n) {
BOOST_ASSERT(n <= size());
// This check is deprecated and is left for backward compatibility. It will be removed in the future.
if ( n > len_ ) if ( n > len_ )
n = len_; n = len_;
len_ -= n; len_ -= n;