Use is_constant_evaluated whenever possible

This commit is contained in:
Krystian Stasiowski
2020-02-19 22:02:41 -05:00
parent a3cba482f9
commit 165f811334
2 changed files with 15 additions and 17 deletions

View File

@ -586,15 +586,8 @@ ptr_in_range(
const T* src_last,
const T* ptr)
{
// We want to make this usable in constant expressions as much as possible
// while retaining the guarentee that the comparison has a strict total ordering.
// We also want this to be fast. Since different compilers have differing levels
// of conformance, we will settle for the best option that is available.
// We don't care about this in C++11, since this function would have
// no applications in constant expressions.
#if defined(BOOST_STATIC_STRING_CPP14) && \
defined(BOOST_STATIC_STRING_NO_PTR_COMP_FUNCTIONS)
#ifdef BOOST_STATIC_STRING_IS_CONST_EVAL
defined(BOOST_STATIC_STRING_IS_CONST_EVAL)
// Our second best option is to use is_constant_evaluated
// and a loop that checks for equality, since equality for
// pointer to object types is never unspecified in this case.
@ -605,17 +598,24 @@ defined(BOOST_STATIC_STRING_NO_PTR_COMP_FUNCTIONS)
return true;
return false;
}
#else
// If library comparison functions don't work, and
// we cannot use any of the above, we can use
// try builtin comparison operators instead.
#endif
// We want to make this usable in constant expressions as much as possible
// while retaining the guarentee that the comparison has a strict total ordering.
// We also want this to be fast. Since different compilers have differing levels
// of conformance, we will settle for the best option that is available.
// We don't care about this in C++11, since this function would have
// no applications in constant expressions.
#if defined(BOOST_STATIC_STRING_CPP14) && \
defined(BOOST_STATIC_STRING_NO_PTR_COMP_FUNCTIONS)
// If library comparison functions don't work,
// we can use try builtin comparison operators instead.
return ptr >= src_first && ptr < src_last;
#endif
#endif
#else
// Use the library comparison functions if we can't use
// is_constant_evaluated or if we don't need to.
return std::greater_equal<const T*>()(ptr, src_first) &&
std::less<const T*>()(ptr, src_last);
#endif
}
} // detail
#endif