forked from boostorg/static_string
Used library comparison functions to compare pointers
This commit is contained in:
@ -574,7 +574,8 @@ find_first_of(
|
||||
return last;
|
||||
}
|
||||
|
||||
// Check if a pointer lies within a range without unspecified behavior, allowing it to be used in a constant evaluation
|
||||
// Check if a pointer lies within a range (inclusive) without unspecified behavior,
|
||||
// allowing it to be used in a constant evaluation
|
||||
template<typename T>
|
||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||
inline
|
||||
@ -584,10 +585,7 @@ is_inside(
|
||||
const T* src_last,
|
||||
const T* ptr)
|
||||
{
|
||||
for (; src_first != src_last; ++src_first)
|
||||
if (src_first == ptr)
|
||||
return true;
|
||||
return false;
|
||||
return std::greater_equal<void>()(ptr, src_first) && std::less_equal<void>()(ptr, src_last);
|
||||
}
|
||||
|
||||
} // detail
|
||||
|
@ -363,15 +363,7 @@ insert(
|
||||
const auto s = &*first;
|
||||
BOOST_STATIC_STRING_THROW_IF(
|
||||
count > max_size() - curr_size, std::length_error{"count > max_size() - size()"});
|
||||
// Makes this more constexpr friendly if we can use is_constant_evaluated
|
||||
const bool inside =
|
||||
#ifdef BOOST_STATIC_STRING_USE_IS_CONST_EVAL
|
||||
std::is_constant_evaluated() ?
|
||||
detail::is_inside(curr_data, curr_data + curr_size, s) :
|
||||
s <= &curr_data[curr_size] && s >= curr_data;
|
||||
#else
|
||||
s <= &curr_data[curr_size] && s >= curr_data;
|
||||
#endif
|
||||
const bool inside = detail::is_inside(curr_data, curr_data + curr_size, s);
|
||||
if (!inside || (inside && ((s - curr_data) + count <= index)))
|
||||
{
|
||||
Traits::move(&curr_data[index + count], &curr_data[index], curr_size - index + 1);
|
||||
@ -669,15 +661,7 @@ replace(
|
||||
curr_size - (std::min)(n1, curr_size - pos) >= max_size() - n2,
|
||||
std::length_error{"replaced string exceeds max_size()"});
|
||||
n1 = (std::min)(n1, curr_size - pos);
|
||||
// Makes this more constexpr friendly if we can use is_constant_evaluated
|
||||
const bool inside =
|
||||
#ifdef BOOST_STATIC_STRING_USE_IS_CONST_EVAL
|
||||
std::is_constant_evaluated() ?
|
||||
detail::is_inside(curr_data, curr_data + curr_size, s) :
|
||||
s <= &curr_data[curr_size] && s >= curr_data;
|
||||
#else
|
||||
s <= &curr_data[curr_size] && s >= curr_data;
|
||||
#endif
|
||||
const bool inside = detail::is_inside(curr_data, curr_data + curr_size, s);
|
||||
if (inside && size_type(s - curr_data) == pos && n1 == n2)
|
||||
return *this;
|
||||
if (!inside || (inside && ((s - curr_data) + n2 <= pos)))
|
||||
|
@ -893,9 +893,9 @@ public:
|
||||
|
||||
Strong guarantee.
|
||||
|
||||
@note
|
||||
The insertion is done unchecked, as the source cannot be
|
||||
within the destination.
|
||||
@note The insertion is done unchecked when
|
||||
the capacity of `str` differs from that of the
|
||||
string the function is called on.
|
||||
|
||||
@note All references, pointers, or iterators
|
||||
referring to contained elements are invalidated. Any
|
||||
@ -921,27 +921,7 @@ public:
|
||||
return insert_unchecked(index, str.data(), str.size());
|
||||
}
|
||||
|
||||
/** Insert a string.
|
||||
|
||||
Inserts the string `str`
|
||||
at the position `index`.
|
||||
|
||||
@par Exception Safety
|
||||
|
||||
Strong guarantee.
|
||||
|
||||
@note All references, pointers, or iterators
|
||||
referring to contained elements are invalidated. Any
|
||||
past-the-end iterators are also invalidated.
|
||||
|
||||
@return `*this`
|
||||
|
||||
@param index The index to insert at.
|
||||
@param str The string to insert.
|
||||
|
||||
@throw std::length_error `size() + str.size() > max_size()`
|
||||
@throw std::out_of_range `index > size()`
|
||||
*/
|
||||
#ifndef GENERATING_DOCUMENTATION
|
||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||
basic_static_string&
|
||||
insert(
|
||||
@ -950,6 +930,7 @@ public:
|
||||
{
|
||||
return insert(index, str.data(), str.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Insert a string.
|
||||
|
||||
@ -960,9 +941,9 @@ public:
|
||||
|
||||
Strong guarantee.
|
||||
|
||||
@note
|
||||
The insertion is done unchecked, as the source cannot be
|
||||
within the destination.
|
||||
@note The insertion is done unchecked when
|
||||
the capacity of `str` differs from that of the
|
||||
string the function is called on.
|
||||
|
||||
@note All references, pointers, or iterators
|
||||
referring to contained elements are invalidated. Any
|
||||
@ -997,31 +978,7 @@ public:
|
||||
return insert_unchecked(index, str.data() + index_str, (std::min)(count, str.size() - index_str));
|
||||
}
|
||||
|
||||
/** Insert a string.
|
||||
|
||||
Inserts a string, obtained by `str.substr(index_str, count)`
|
||||
at the position `index`.
|
||||
|
||||
@par Exception Safety
|
||||
|
||||
Strong guarantee.
|
||||
|
||||
@note All references, pointers, or iterators
|
||||
referring to contained elements are invalidated. Any
|
||||
past-the-end iterators are also invalidated.
|
||||
|
||||
@return `*this`
|
||||
|
||||
@param index The index to insert at.
|
||||
@param str The string from which to insert.
|
||||
@param index_str The index in `str` to start inserting from.
|
||||
@param count The number of characters to insert.
|
||||
The default argument for this parameter is @ref npos.
|
||||
|
||||
@throw std::length_error `size() + str.substr(index_str, count).size() > max_size()`
|
||||
@throw std::out_of_range `index > size()`
|
||||
@throw std::out_of_range `index_str > str.size()`
|
||||
*/
|
||||
#ifndef GENERATING_DOCUMENTATION
|
||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||
basic_static_string&
|
||||
insert(
|
||||
@ -1035,6 +992,7 @@ public:
|
||||
);
|
||||
return insert(index, str.data() + index_str, (std::min)(count, str.size() - index_str));
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Insert a character.
|
||||
|
||||
@ -1944,7 +1902,6 @@ public:
|
||||
swap(
|
||||
basic_static_string<M, CharT, Traits>& s) BOOST_STATIC_STRING_NO_EXCEPTIONS_NOEXCEPT;
|
||||
|
||||
|
||||
/** Replace a substring with a string.
|
||||
|
||||
Replaces `rcount` characters starting at index `pos1` with those
|
||||
@ -1954,9 +1911,9 @@ public:
|
||||
|
||||
Strong guarantee.
|
||||
|
||||
@note
|
||||
The replacement is done unchecked, as the source cannot be
|
||||
within the destination.
|
||||
@note The replacement is done unchecked when
|
||||
the capacity of `str` differs from that of the
|
||||
string the function is called on.
|
||||
|
||||
All references, pointers, or iterators
|
||||
referring to contained elements are invalidated. Any
|
||||
@ -1984,28 +1941,7 @@ public:
|
||||
return replace_unchecked(pos1, n1, str.data(), str.size());
|
||||
}
|
||||
|
||||
/** Replace a substring with a string.
|
||||
|
||||
Replaces `rcount` characters starting at index `pos1` with those
|
||||
of `str`, where `rcount` is `std::min(n1, size() - pos1)`.
|
||||
|
||||
@par Exception Safety
|
||||
|
||||
Strong guarantee.
|
||||
|
||||
@note All references, pointers, or iterators
|
||||
referring to contained elements are invalidated. Any
|
||||
past-the-end iterators are also invalidated.
|
||||
|
||||
@return `*this`
|
||||
|
||||
@param pos1 The index to replace at.
|
||||
@param n1 The number of characters to replace.
|
||||
@param str The string to replace with.
|
||||
|
||||
@throw std::length_error `size() + (str.size() - rcount) > max_size()`
|
||||
@throw std::out_of_range `pos1 > size()`
|
||||
*/
|
||||
#ifndef GENERATING_DOCUMENTATION
|
||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||
basic_static_string&
|
||||
replace(
|
||||
@ -2015,6 +1951,7 @@ public:
|
||||
{
|
||||
return replace(pos1, n1, str.data(), str.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Replace a substring with a substring.
|
||||
|
||||
@ -2025,50 +1962,9 @@ public:
|
||||
|
||||
Strong guarantee.
|
||||
|
||||
@note All references, pointers, or iterators
|
||||
referring to contained elements are invalidated. Any
|
||||
past-the-end iterators are also invalidated.
|
||||
|
||||
@return `*this`
|
||||
|
||||
@param pos1 The index to replace at.
|
||||
@param n1 The number of characters to replace.
|
||||
@param str The string to replace with.
|
||||
@param pos2 The index to begin the substring.
|
||||
@param n2 The length of the substring.
|
||||
The default argument for this parameter is @ref npos.
|
||||
|
||||
@throw std::length_error `size() + (std::min(str.size(), n2) - rcount) > max_size()`
|
||||
@throw std::out_of_range `pos1 > size()`
|
||||
@throw std::out_of_range `pos2 > str.size()`
|
||||
*/
|
||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||
basic_static_string&
|
||||
replace(
|
||||
size_type pos1,
|
||||
size_type n1,
|
||||
const basic_static_string& str,
|
||||
size_type pos2,
|
||||
size_type n2 = npos) BOOST_STATIC_STRING_NO_EXCEPTIONS_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_STRING_THROW_IF(
|
||||
pos2 > str.size(), std::out_of_range{"pos2 > str.size()"}
|
||||
);
|
||||
return replace(pos1, n1, str.data() + pos2, (std::min)(n2, str.size() - pos2));
|
||||
}
|
||||
|
||||
/** Replace a substring with a substring.
|
||||
|
||||
Replaces `rcount` characters starting at index `pos1` with those of
|
||||
`str.subview(pos2, n2)`, where `rcount` is `std::min(n1, size() - pos1)`.
|
||||
|
||||
@par Exception Safety
|
||||
|
||||
Strong guarantee.
|
||||
|
||||
@note
|
||||
The replacement is done unchecked, as the source cannot be
|
||||
within the destination.
|
||||
@note The replacement is done unchecked when
|
||||
the capacity of `str` differs from that of the
|
||||
string the function is called on.
|
||||
|
||||
All references, pointers, or iterators
|
||||
referring to contained elements are invalidated. Any
|
||||
@ -2103,6 +1999,23 @@ public:
|
||||
return replace_unchecked(pos1, n1, str.data() + pos2, (std::min)(n2, str.size() - pos2));
|
||||
}
|
||||
|
||||
#ifndef GENERATING_DOCUMENTATION
|
||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||
basic_static_string&
|
||||
replace(
|
||||
size_type pos1,
|
||||
size_type n1,
|
||||
const basic_static_string& str,
|
||||
size_type pos2,
|
||||
size_type n2 = npos) BOOST_STATIC_STRING_NO_EXCEPTIONS_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_STRING_THROW_IF(
|
||||
pos2 > str.size(), std::out_of_range{"pos2 > str.size()"}
|
||||
);
|
||||
return replace(pos1, n1, str.data() + pos2, (std::min)(n2, str.size() - pos2));
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Replace a substring with an object convertible to `string_view_type`.
|
||||
|
||||
Constructs a temporary `string_view_type` object `sv` from `t`, and
|
||||
|
Reference in New Issue
Block a user