mirror of
https://github.com/boostorg/utility.git
synced 2025-05-08 18:34:02 +00:00
Added string_view/ref::substr overloads taking no arguments.
This effectively adds support for pos=0 default argument value. The separate overload is better as it avoids instantiating std::min, boost::throw_exception and removes std::out_of_range construction, which potentially reduces code size, while maintaining the same behavior. Fixes https://github.com/boostorg/utility/issues/96.
This commit is contained in:
parent
0c1d01d30a
commit
0106ffda5f
@ -161,6 +161,10 @@ namespace boost {
|
||||
|
||||
|
||||
// basic_string_ref string operations
|
||||
basic_string_ref substr() const {
|
||||
return basic_string_ref(data(), size());
|
||||
}
|
||||
|
||||
basic_string_ref substr(size_type pos, size_type n=npos) const {
|
||||
if ( pos > size())
|
||||
BOOST_THROW_EXCEPTION( std::out_of_range ( "string_ref::substr" ) );
|
||||
|
@ -189,6 +189,10 @@ namespace boost {
|
||||
return rlen;
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR basic_string_view substr() const {
|
||||
return basic_string_view(data(), size());
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR basic_string_view substr(size_type pos, size_type n=npos) const {
|
||||
if ( pos > size())
|
||||
BOOST_THROW_EXCEPTION( std::out_of_range ( "string_view::substr" ) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user