forked from boostorg/static_string
More constexpr friendly replace and insert with is_constant_evaluated
This commit is contained in:
@ -25,6 +25,16 @@
|
|||||||
#define BOOST_STATIC_STRING_USE_DEDUCT
|
#define BOOST_STATIC_STRING_USE_DEDUCT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Include <version> if we can
|
||||||
|
#if __has_include(<version>)
|
||||||
|
#include <version>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Can we use is_constant_evaluated?
|
||||||
|
#if __cpp_lib_is_constant_evaluated >= 201811L
|
||||||
|
#define BOOST_STATIC_STRING_USE_IS_CONST_EVAL
|
||||||
|
#endif
|
||||||
|
|
||||||
// Can we use [[nodiscard]]?
|
// Can we use [[nodiscard]]?
|
||||||
#ifdef __has_attribute
|
#ifdef __has_attribute
|
||||||
#if __has_attribute(nodiscard)
|
#if __has_attribute(nodiscard)
|
||||||
|
@ -363,7 +363,15 @@ insert(
|
|||||||
const auto s = &*first;
|
const auto s = &*first;
|
||||||
BOOST_STATIC_STRING_THROW_IF(
|
BOOST_STATIC_STRING_THROW_IF(
|
||||||
count > max_size() - curr_size, std::length_error{"count > max_size() - size()"});
|
count > max_size() - curr_size, std::length_error{"count > max_size() - size()"});
|
||||||
const bool inside = s <= &curr_data[curr_size] && s >= curr_data;
|
// 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
|
||||||
if (!inside || (inside && ((s - curr_data) + count <= index)))
|
if (!inside || (inside && ((s - curr_data) + count <= index)))
|
||||||
{
|
{
|
||||||
Traits::move(&curr_data[index + count], &curr_data[index], curr_size - index + 1);
|
Traits::move(&curr_data[index + count], &curr_data[index], curr_size - index + 1);
|
||||||
@ -683,7 +691,15 @@ replace(
|
|||||||
curr_size - (std::min)(n1, curr_size - pos) >= max_size() - n2,
|
curr_size - (std::min)(n1, curr_size - pos) >= max_size() - n2,
|
||||||
std::length_error{"replaced string exceeds max_size()"});
|
std::length_error{"replaced string exceeds max_size()"});
|
||||||
n1 = (std::min)(n1, curr_size - pos);
|
n1 = (std::min)(n1, curr_size - pos);
|
||||||
const bool inside = s <= &curr_data[curr_size] && s >= curr_data;
|
// 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
|
||||||
if (inside && size_type(s - curr_data) == pos && n1 == n2)
|
if (inside && size_type(s - curr_data) == pos && n1 == n2)
|
||||||
return *this;
|
return *this;
|
||||||
if (!inside || (inside && ((s - curr_data) + n2 <= pos)))
|
if (!inside || (inside && ((s - curr_data) + n2 <= pos)))
|
||||||
|
@ -191,6 +191,11 @@ testConstantEvaluation()
|
|||||||
a.replace(a.begin(), a.end(), a.begin(), a.end());
|
a.replace(a.begin(), a.end(), a.begin(), a.end());
|
||||||
a.replace(a.begin(), a.end(), {'a'});
|
a.replace(a.begin(), a.end(), {'a'});
|
||||||
|
|
||||||
|
#ifdef BOOST_STATIC_STRING_USE_IS_CONST_EVAL
|
||||||
|
a.replace(a.begin(), a.end(), "a");
|
||||||
|
a.replace(a.begin(), a.end(), "a", 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
// find
|
// find
|
||||||
a.find(a);
|
a.find(a);
|
||||||
a.find("a", 0, 1);
|
a.find("a", 0, 1);
|
||||||
|
Reference in New Issue
Block a user